PromiseShim

new PromiseShim(agent, moduleName, resolvedName, shimName, pkgVersion)

Constructs a shim associated with the given agent instance, specialized for instrumenting promise libraries.

Parameters:
NameTypeDescription
agentAgent

The agent this shim will use.

moduleNamestring

The name of the module being instrumented.

resolvedNamestring

The full path to the loaded module.

shimNamestring

Used to persist shim ids across different shim instances.

pkgVersionstring

version of module

See

Methods

isPromiseInstance(obj) → {boolean}

Checks if the given object is an instance of a promise from the promise library being wrapped.

Parameters:
NameTypeDescription
obj*

The object to check the instance type of.

Returns:

True if the provided object is an instance of a promise from this promise library.

Type: 
boolean

setClass(clss)

Sets the class used to identify promises from the wrapped promise library.

Parameters:
NameTypeDescription
clssfunction

The promise library's class.

wrapCast(nodule, propertiesopt) → {object|function}

Wraps the given properties as methods which take is some value other than a function to call and return a promise.

  • wrapCast(nodule, properties)
  • wrapCast(func)

Examples of promise cast methods include Promise.resolve, Promise.all, and Bluebird's Promise.delay. These are static methods which accept some arbitrary value and return a Promise instance.

Parameters:
NameTypeAttributesDescription
noduleobject | function

The source of the properties to wrap, or a single function to wrap.

propertiesstring | Array.<string><optional>

One or more properties to wrap. If omitted, the nodule parameter is assumed to be the function to wrap.

Returns:

The first parameter to this function, after wrapping it or its properties.

Type: 
object | function

wrapCatch(nodule, propertiesopt) → {object|function}

Wraps the given properties as rejected promise chaining methods.

  • wrapCatch(nodule, properties)
  • wrapCatch(func)

NOTE: You must set class used by the library before wrapping catch-methods.

Promise catch methods differ from then methods in that only one function will be executed and only if the promise is rejected. Some libraries accept an additional argument to Promise#catch which is usually an error class to filter rejections by. This wrap method will handle that case.

Parameters:
NameTypeAttributesDescription
noduleobject | function

The source of the properties to wrap, or a single function to wrap.

propertiesstring | Array.<string><optional>

One or more properties to wrap. If omitted, the nodule parameter is assumed to be the function to wrap.

Returns:

The first parameter to this function, after wrapping it or its properties.

Type: 
object | function

wrapConstructor(nodule, propertiesopt) → {object|function}

Wraps the given properties as constructors for the promise library.

  • wrapConstructor(nodule, properties)
  • wrapConstructor(func)

It is only necessary to wrap the constructor for the class if there is no other way to access the executor function. Some libraries expose a separate method which is called to execute the executor. If that is available, it is better to wrap that using PromiseShim#wrapExecutorCaller than to use this method.

Parameters:
NameTypeAttributesDescription
noduleobject | function

The source of the properties to wrap, or a single function to wrap.

propertiesstring | Array.<string><optional>

One or more properties to wrap. If omitted, the nodule parameter is assumed to be the constructor to wrap.

Returns:

The first parameter to this function, after wrapping it or its properties.

Type: 
object | function

wrapExecutorCaller(nodule, propertiesopt) → {object|function}

Wraps the given properties as the caller of promise executors.

  • wrapExecutorCaller(nodule, properties)
  • wrapExecutorCaller(func)

Wrapping the executor caller method directly is preferable to wrapping the constructor of the promise class.

Parameters:
NameTypeAttributesDescription
noduleobject | function

The source of the properties to wrap, or a single function to wrap.

propertiesstring | Array.<string><optional>

One or more properties to wrap. If omitted, the nodule parameter is assumed to be the function to wrap.

Returns:

The first parameter to this function, after wrapping it or its properties.

Type: 
object | function

wrapPromisify(nodule, propertiesopt) → {object|function}

Wraps the given properties as callback-to-promise conversion methods.

  • wrapPromisify(nodule, properties)
  • wrapPromisify(func)
Parameters:
NameTypeAttributesDescription
noduleobject | function

The source of the properties to wrap, or a single function to wrap.

propertiesstring | Array.<string><optional>

One or more properties to wrap. If omitted, the nodule parameter is assumed to be the function to wrap.

Returns:

The first parameter to this function, after wrapping it or its properties.

Type: 
object | function

wrapThen(nodule, propertiesopt) → {object|function}

Wraps the given properties as promise chaining methods.

  • wrapThen(nodule, properties)
  • wrapThen(func)

NOTE: You must set class used by the library before wrapping then-methods.

Examples of promise then methods include Promise#then, Promise#finally, and Bluebird's Promise#map. These are methods which take a function to execute once the promise resolves and hands back a new promise.

Parameters:
NameTypeAttributesDescription
noduleobject | function

The source of the properties to wrap, or a single function to wrap.

propertiesstring | Array.<string><optional>

One or more properties to wrap. If omitted, the nodule parameter is assumed to be the function to wrap.

Returns:

The first parameter to this function, after wrapping it or its properties.

Type: 
object | function