Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
handle: function (args, shouldExit) {
var result;
if (!args || args.length == 2) {
result = this.runCommand("help");
}
else if (args.length >= 2) {
result = this.runCommand(args[2], args.slice(3));
}
if (when.isPromiseLike(result)) {
when(result).catch(function(err) {
if (shouldExit) {
process.exit(1);
}
});
}
else {
return result;
}
// else {
// if (shouldExit) {
// process.exit(parseInt(result));
// }
// else {
// return result;
// }
error({ error: err.message });
}
// if function is generator then wait on yield
if (util.isES6Function(handlerFunc)) {
try {
// result is generator, so co wrapper it and turn into promise
result = co(result);
}
catch (err) {
error({ error: err.message });
}
}
// if result is promise, fire done on the result data
if (when.isPromiseLike(result)) {
result.then(function (output) {
// TODO: figure out better way to handle combined input/vs just data
// API breaking change?
if (output && output.data && output.code) {
done(output.data, output.code, output.headers);
}
else {
done(output);
}
})
.catch(function (err) {
error({ error: err });
});
}
// if result is not promise and not null or undefined
else if (_.isObject(result) && result.data && result.code) {
ObjectAdapter.canHandle = function (obj) {
// this seems close enough to ensure that instanceof works.
// a RegExp will pass as a valid prototype, but I am not sure
// this is a bad thing even if it is unusual.
// IMPORTANT: since promises *are* objects, the check for isPromise
// must come first in the OR
return obj && (when.isPromiseLike(obj) || Object.prototype.toString.call(obj) == '[object Object]');
};
request: function () {}
},
devOptions
);
var returnedPromise = requestFunc({
body: {
input: {},
http: {
headers: {},
body: '{}'
}
}
});
assert(when.isPromiseLike(returnedPromise));
var requestFunc2 = bindTriggerRequest(
{
request: {}
},
devOptions
);
var returnedPromise2 = requestFunc2({
body: {
input: {},
http: {
headers: {},
body: '{}'
}
var noPromise = query('SELECT NOW() as when', function(err, rows, result) {
if(err) return done(err);
assert(!when.isPromiseLike(noPromise));
assert(util.isArray(rows));
assert.equal(rows.length, 1);
assert.equal(rows, result.rows);
done();
});
});
it('should provide a promise from "runJob"', function() {
var returned = boundRunJob();
expect(when.isPromiseLike(returned)).to.equal(true);
});
it('should return a promise from "sort"', function() {
//noinspection BadExpressionStatementJS,JSUnresolvedFunction,JSUnresolvedVariable
expect(when.isPromiseLike(promise)).to.be.true;
});
it('returns a promise', function() {
expect(when.isPromiseLike(promise)).to.be.true;
});
it('returns a promise from "enableWorker"', function() {
var enablePromise = config.enableWorker();
expect(when.isPromiseLike(enablePromise));
enablePromise.done(noop, noop);
});
handle(args, shouldExit) {
let result;
if (!args || args.length === 2) {
result = this.runCommand('help');
} else if (args.length >= 2) {
result = this.runCommand(args[2], args.slice(3));
}
if (when.isPromiseLike(result)) {
result.done((res) => {
process.exit(+res || 0);
}, () => {
if (shouldExit) {
process.exit(1);
}
});
} else {
if (result !== undefined) {
process.exit(result === 0 ? 0 : 1);
return;
}
}
}