Security News
UK Officials Consider Banning Ransomware Payments from Public Entities
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.
Simple and clean asynchronous processing.
Repository:
git clone git://github.com/cho45/jsdeferred.git
Copy and paste following at end of your userscript:
Example:
with (D()) {
next(fun...);
// normal xhr
http.get("...").
next(fun...);
// cross site
xhttp.get("...").
next(fun...);
}
// pasted code
function D () {
...JSDeferred...
}
See binding/userscript.js to get more information of utility functions (http.get/xhttp.get)
See source.
Copyright 2007-2009 cho45 <cho45@lowreal.net>
MIT. See header of jsdeferred.js
This sections use some words as following meanings.
chain:: a sequence of processes. child:: the Deferred which returns from a callback. Deferred#foobar:: Deferred.prototype.foobar
A Deferred object has only one callback as its process. Deferred object packages a process (function) as callback and has reference to next Deferred (this is thought like continuation).
Example for understanding Deferred structure.
var d1 = new Deferred();
d1.callback.ok = function () {
alert("1");
};
var d2 = new Deferred();
d2.callback.ok = function () {
alert("2");
};
// Set d2 as continuation of d1.
d1._next = d2;
// Invoke the chain.
d1.call();
And example for usual use.
next(function () { // this `next` is global function
alert("1");
}).
next(function () { // this `next` is Deferred#next
alert("2");
}).
next(function () {
alert("3");
});
Deferred#next creates new Deferred, sets the passed functions to process of it, sets it as continuation of this
and returns it.
This structure makes easy to chain child Deferreds.
next(function () {
alert("1");
}).
next(function () {
alert("2");
// child Deferred
return next(function () {
alert("3");
});
}).
next(function () {
alert("4");
});
When the callback returns Deferred, the Deferred calling the callback only sets its continuation (_next
) to returned Deferred's continuation.
next(function () {
alert("1");
}).
next(function () {
alert("2");
var d = next(function () {
alert("3");
});
d._next = this._next;
this.cancel();
}).
next(function () {
alert("4");
});
After the process, above code is same as following:
next(function () {
alert("1");
}).
next(function () {
alert("2");
next(function () {
alert("3");
}).
next(function () {
alert("4");
});
});
A Deferred has also error-back for error processing. Let's just see an example (this is from test):
next(function () {
throw "Error";
}).
error(function (e) {
expect("Errorback called", "Error", e);
return e; // recovering error
}).
next(function (e) {
expect("Callback called", "Error", e);
throw "Error2";
}).
next(function (e) {
// This process is not called because
// the error is not recovered.
ng("Must not be called!!");
}).
error(function (e) {
expect("Errorback called", "Error2", e);
});
The error thrown in callback is propagated by error-back chain. If the error-back returns normal value, the error is considered as recovery, and the callback chain continues.
JSDeferred is inspired by MochiKit Deferred object, so both is similar but JSDeferred drops some functions and simplified it.
JSDeferred can be used in inter-environment which is independent respectively like browser extension because JSDeferred determines a self-class identity by instance id.
Copyright 2007-2009 cho45 <cho45@lowreal.net>
FAQs
Asynchronous library in JavaScript. Standalone and Compact.
The npm package jsdeferred receives a total of 0 weekly downloads. As such, jsdeferred popularity was classified as not popular.
We found that jsdeferred demonstrated a not healthy version release cadence and project activity because the last version was released 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
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.
Security News
Snyk's use of malicious npm packages for research raises ethical concerns, highlighting risks in public deployment, data exfiltration, and unauthorized testing.
Research
Security News
Socket researchers found several malicious npm packages typosquatting Chalk and Chokidar, targeting Node.js developers with kill switches and data theft.