Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
async-compat
Advanced tools
Compatibility functions for writing libraries that support synchronous, callback and promise signatures
Compatibility functions for writing libraries that support synchronous, callback and promise signatures.
It handles both the call signature differences between callback and promises APIs (eg. missing the last callback parameter) by converting them to callbacks. It also resolves returned parameters when promises are returned.
var compat = require('async-compat');
var assert = require(assert');
/////////////////
// synchronous
/////////////////
function fn(value1) {
assert.equal(value1, 1);
return 4;
}
compat.asyncFunction(fn, false /* no callbacks */, 1, function (err, result) {
assert.ok(!err, err ? err.message : '');
assert.equal(result, 4);
});
function errorFn(value1) {
assert.equal(value1, 1);
return new Error('Failed');
}
compat.asyncFunction(errorFn, false /* no callbacks */, 1, function (err, result) {
assert.ok(!!err);
});
/////////////////
// callback
/////////////////
function callbackFn(value1, callback) {
assert.equal(value1, 1);
callback(null, 4);
}
compat.asyncFunction(callbackFn, true /* no callbacks */, 1, function (err, result) {
assert.ok(!err, err ? err.message : '');
assert.equal(result, 4);
});
function errorCallbackFn(value1, callback) {
assert.equal(value1, 1);
callback(new Error('Failed'));
}
compat.asyncFunction(errorCallbackFn, true /* no callbacks */, 1, function (err, result) {
assert.ok(!!err);
});
/////////////////
// promise
/////////////////
function promiseFn(value1) {
assert.equal(value1, 1);
return Promise.resolve(4);
}
compat.asyncFunction(promiseFn, false /* no callbacks */, 1, function (err, result) {
assert.ok(!err, err ? err.message : '');
assert.equal(result, 4);
});
function errorPromiseFn(value1) {
assert.equal(value1, 1);
return Promise.reject(new Error('Failed'));
}
compat.errorPromiseFn(promiseFn, false /* no callbacks */, 1, function (err, result) {
assert.ok(!!err);
});
FAQs
Compatibility functions for writing libraries that support synchronous, callback and promise signatures
The npm package async-compat receives a total of 18,430 weekly downloads. As such, async-compat popularity was classified as popular.
We found that async-compat demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.