initcb
- initcb([successHandler[, errorHandler[, ...initArgs]]])
Asynchronously initialize the dcp-client bundle. Same as init(), except that it doesn’t return a Promise – it invokes callbacks instead.
- Arguments:
successHandler (function) – Optional. Invoked, with no arguments, once initialization succeeds.
errorHandler (function) – Optional. Invoked with the Error if initialization fails. If omitted, the error is instead re-thrown asynchronously (via
setImmediate), which will crash an uncaught-exception-intolerant process.initArgs – Any further arguments are passed through to init() as-is – so, for example,
initcb(onSuccess, onError, { scheduler: url })works.
Note
successHandler and errorHandler are detected positionally by type, not by position alone: whichever of the first one or two arguments are actually functions get consumed as the callbacks, and whatever’s left (including a case where neither argument is a function) is forwarded to init(). Passing something that isn’t a function reference where a callback is expected (e.g. initcb(main()) instead of initcb(main)) means it won’t be recognized as successHandler at all, and if it survives to be forwarded into init()’s argument list, will likely cause init() to throw or misbehave instead.
Example:
const { initcb } = require('dcp-client');
async function main() {
/* DCP App ... */
}
initcb(main, (err) => {
console.error(err);
process.exit(1);
});