Security News
38% of CISOs Fear They’re Not Moving Fast Enough on AI
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
@avocode/cancel-token
Advanced tools
A method for making async operations cancellable
Component:
$ component install ForbesLindesay/cancellation
NPM:
$ npm install cancellation
Returns a new CancellationTokenSource:
var tokenSource = require('cancellation');
var source = tokenSource();
callAsyncOperation(arg1, arg2, arg3, source.token);
setTimeout(function () {
source.cancel('Operation timed out');
}, 1000);
Returns an 'empty' CancellationToken (one that will never be cancelled).
var tokenSource = require('cancellation');
function asyncOperation(arg1, arg2, arg3, cancellationToken) {
cancellationToken = cancellationToken || tokenSource.empty;
//Continue with function knowing there is a cancellation token
}
Returns true if the token has been cancelled:
//In ES6
function asyncOperation(cancellationToken) {
return spawn(function* () {
while(!cancellationToken.isCancelled()) {
yield NextAsyncOp();
}
})
}
Throws the rejection reason if the token has been cancelled:
//In ES6
function asyncOperation(cancellationToken) {
return spawn(function* () {
while(true) {
cancellationToken.throwIfCancelled()
yield NextAsyncOp();
}
})
}
Calls cb when the cancellation token is cancelled (this is probably currently the most useful of these methods).
function get(url, cancellationToken) {
var def = defer();
var req = request(url, function (err, res) {
if (err) def.reject(err);
else def.resolve(res);
});
cancellationToken
.onCancelled(function (reason) {
def.reject(reason);
req.abort();
});
return def.promise;
}
MIT
FAQs
A method for making async operations cancellable
The npm package @avocode/cancel-token receives a total of 6 weekly downloads. As such, @avocode/cancel-token popularity was classified as not popular.
We found that @avocode/cancel-token demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 18 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
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
Research
Security News
Socket researchers uncovered a backdoored typosquat of BoltDB in the Go ecosystem, exploiting Go Module Proxy caching to persist undetected for years.
Security News
Company News
Socket is joining TC54 to help develop standards for software supply chain security, contributing to the evolution of SBOMs, CycloneDX, and Package URL specifications.