new PromiseShim(agent, moduleName, resolvedName, shimName, pkgVersion)
Constructs a shim associated with the given agent instance, specialized for instrumenting promise libraries.
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. |
shimName | string | Used to persist shim ids across different shim instances. |
pkgVersion | string | version of module |
- Source
- See
Methods
isPromiseInstance(obj) → {boolean}
Checks if the given object is an instance of a promise from the promise library being wrapped.
Name | Type | Description |
---|---|---|
obj | * | The object to check the instance type of. |
- Source
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.
Name | Type | Description |
---|---|---|
clss | function | The promise library's class. |
- Source
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.
Name | Type | Attributes | Description |
---|---|---|---|
nodule | object | | The source of the properties to wrap, or a single function to wrap. | |
properties | string | | <optional> | One or more properties to wrap. If omitted, the |
- Source
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.
Name | Type | Attributes | Description |
---|---|---|---|
nodule | object | | The source of the properties to wrap, or a single function to wrap. | |
properties | string | | <optional> | One or more properties to wrap. If omitted, the |
- Source
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.
Name | Type | Attributes | Description |
---|---|---|---|
nodule | object | | The source of the properties to wrap, or a single function to wrap. | |
properties | string | | <optional> | One or more properties to wrap. If omitted, the |
- Source
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.
Name | Type | Attributes | Description |
---|---|---|---|
nodule | object | | The source of the properties to wrap, or a single function to wrap. | |
properties | string | | <optional> | One or more properties to wrap. If omitted, the |
- Source
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)
Name | Type | Attributes | Description |
---|---|---|---|
nodule | object | | The source of the properties to wrap, or a single function to wrap. | |
properties | string | | <optional> | One or more properties to wrap. If omitted, the |
- Source
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.
Name | Type | Attributes | Description |
---|---|---|---|
nodule | object | | The source of the properties to wrap, or a single function to wrap. | |
properties | string | | <optional> | One or more properties to wrap. If omitted, the |
- Source
The first parameter to this function, after wrapping it or its properties.
- Type:
- object |
function