@itentialopensource/itentialpromisify
v1.1.3
Published
A generic class that wraps cogs, adapters, etc. so that their functions return promises.
Downloads
7,179
Keywords
Readme
ItentialPromisify
ItentialPromisify wraps cog and adapter functions to enable using async/await with them.
You can also use ItentialPromisify to promisify a single function that expects a callback with arguments in the order results, error.
Installation
npm install --save @itentialopensource/itentialpromisify
Usage with cogs/adapters
Require
ItentialPromisfy
.const itentialPromisify = require('@itentialopensource/itentialPromisify');
Wrap an
adapter
orcog
.const workFlowEngineWrapper = itentialPromisify(cogs.WorkFlowEngine);
Use
async
/await
with any method from the cog you wrapped.try { const workflowName = 'routerUpgrade'; const options = { variables: { new_version: '1.8.8' } }; // N.b. no need to pass a callback to the wrapper! const saveData = await workFlowEngineWrapper.startJobWithOptions(workflowName, options); console.log(JSON.stringify(saveData, null, 2)); } catch (error) { console.log(error.stack); }
Usage with single functions
Require
ItentialPromisfy
.const itentialPromisify = require('@itentialopensource/itentialPromisify');
Call itentialPromisify on the function
const startJobWithOptionsPromisified = itentialPromisify(cogs.WorkFlowEngine.startJobWithOptions);
Use
async
/await
with the promisified method.try { const workflowName = 'routerUpgrade'; const options = { variables: { new_version: '1.8.8' } }; const saveData = await startJobWithOptionsPromisified(workflowName, options); console.log(JSON.stringify(saveData, null, 2)); } catch (error) { console.log(error.stack); }
:open_hands: Contributing to itentialPromisify
Please check out the Contributing Guidelines.
License & Maintainers
Maintained by:
Itential Cloud & Delivery Support Teams