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:
module VisitorCenter
{
interface Greeter
{
string greet(string name);
}
}
The generated JavaScript skeleton class is:
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:
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:
greet(name: string, current: Ice.Current): PromiseLike<string> | string {
return `Hello, ${name}`;
}
Asynchronous version:
async greet(name: string, current: Ice.Current): PromiseLike<string> | string {
// Nested async invocation
return await this._target.greet(name);
}