PromiseShim

PromiseShim

new PromiseShim(agent, moduleName, resolvedName)

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

Source:
See:
Parameters:
Name Type Description
agent Agent

The agent this shim will use.

moduleName string

The name of the module being instrumented.

resolvedName string

The full path to the loaded module.

Methods

isPromiseInstance(obj) → {bool}

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

Source:
See:
Parameters:
Name Type Description
obj *

The object to check the instance type of.

Returns:
Type:
bool

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

setClass(clss)

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

Source:
Parameters:
Name Type Description
clss function

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.

Source:
Parameters:
Name Type Attributes Description
nodule object | function

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

properties string | array.<string> <optional>

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

Returns:
Type:
object | function

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

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.

Source:
See:
Parameters:
Name Type Attributes Description
nodule object | function

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

properties string | array.<string> <optional>

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

Returns:
Type:
object | function

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

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.

Source:
See:
Parameters:
Name Type Attributes Description
nodule object | function

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

properties string | array.<string> <optional>

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

Returns:
Type:
object | function

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

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.

Source:
See:
Parameters:
Name Type Attributes Description
nodule object | function

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

properties string | array.<string> <optional>

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

Returns:
Type:
object | function

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

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

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

  • wrapPromisify(nodule, properties)
  • wrapPromisify(func)
Source:
Parameters:
Name Type Attributes Description
nodule object | function

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

properties string | array.<string> <optional>

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

Returns:
Type:
object | function

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

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.

Source:
See:
Parameters:
Name Type Attributes Description
nodule object | function

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

properties string | array.<string> <optional>

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

Returns:
Type:
object | function

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