Skip to main content
Skip table of contents

Server-Side JavaScript Mapping for Operations

For each Slice operation defined on an interface, the generated skeleton class includes a corresponding abstract member function with the same name.

For example, consider the following Slice definition:

SLICE
module VisitorCenter
{
    interface Greeter
    {
        string greet(string name);
    }
}

The generated JavaScript skeleton class is:

JS
VisitorCenter.Greeter = class extends Ice.Object {};

Since JavaScript does not support abstract methods, the generated class does not provide an actual abstract declaration. Instead, the servant class that derives from this skeleton must add the operation implementations, as if the methods were abstract.

This is clearer in the generated TypeScript declarations, which can use abstract methods:

TYPESCRIPT
export abstract class Greeter extends Ice.Object {
    abstract greet(
        name: string,
        current: Ice.Current): PromiseLike<string> | string;
    ...

The servant implementation can choose how to provide the result:

  • Return the result directly (synchronous implementation).

  • Return a promise-like object that will be fulfilled with the result.

  • Declare the method as async and use await inside the implementation.

Synchronous version:

TYPESCRIPT
greet(name: string, current: Ice.Current): PromiseLike<string> | string {
    return `Hello, ${name}`;
}

Asynchronous version:

TYPESCRIPT
async greet(name: string, current: Ice.Current): PromiseLike<string> | string {
    // Nested async invocation
    return await this._target.greet(name);
}

JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.