1.1.2 • Published 7 years ago

ice-utils v1.1.2

Weekly downloads
2
License
GPL-2.0
Repository
github
Last release
7 years ago

Ice Utils npm version Build Status

A set of utilities that makes using ZeroC ICE with JS easier.

Installation

npm install --save ice-utils

API

toPromise(icePromise: Ice.Promise): Promise

Turn Ice promise to normal one. Useful with async/await because awaiting Ice promises leads to infinite loops.

Example

async function fn() {
  const icePromise = myPrx.someOperation();
  
  const result = await toPromise(icePromise);
  
  return result;
} 

numberToLong(num: number): Ice.Long

Convert number to Ice.Long. Ice only provides method to convert Ice.Long to number, but reverse conversion is necessary if you need to supply operation parameter of type long, or implement a servant method that returns long.

See JavaScript Mapping for Long Integers.

operation(name?: string): MethodDecorator

Decorator factory for convenient operation implementation on servants.

Automatically adds ["amd"] metadata because sync operations make little sense in JS world.

Parameters

  • name: Operation name. Defaults to decorated method name.

Example

class MyServant extends MySlices.MyServant {
  @operation()
  myOperation() {
    return doSomeStuff()
     .then(doSomeOtherStuff);
  }
}

Example

class MyServant extends MySlices.MyServant {
  @operation()
  async myOperation() {
    const result = await doSomeStuff();
    return result;
  }
}

handleDispatchException(handler: IceErrorHandler): RemoveIceErrorHandler

Add a hook for handling uncaught dispatch errors. Ice.Warn.Dispatch must be turned on.

Default error logging is disabled if custom handler is assigned.

Example

const removeHandler = handleDispatchException((error, context, current) => {
  const {requestId, operation, id} = current;
  console.error(error, {
    ...context,
    iceRequestId: requestId,
    iceOperation: operation,
    iceIdentity: Ice.identityToString(id)
  });
});
1.1.2

7 years ago

1.1.1

7 years ago

1.1.0

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago