在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:mozilla/task.js开源软件地址:https://github.com/mozilla/task.js开源编程语言:JavaScript 100.0%开源软件介绍:task.js
task.js provides an automatic task scheduler along with a library of first-class, synchronizable events, making it easy to do I/O without callbacks. With task.js you can write non-blocking I/O in a synchronous style, even with error handling: spawn(function*() {
try {
var [foo, bar] = yield join(read("foo.json"),
read("bar.json")).timeout(1000);
render(foo);
render(bar);
} catch (e) {
console.log("read failed: " + e);
}
}); Compared with callbacks: var foo, bar;
var tid = setTimeout(function() { failure(new Error("timed out")) }, 1000);
var xhr1 = makeXHR("foo.json",
function(txt) { foo = txt; success() },
function(err) { failure() });
var xhr2 = makeXHR("bar.json",
function(txt) { bar = txt; success() },
function(e) { failure(e) });
function success() {
if (typeof foo === "string" && typeof bar === "string") {
cancelTimeout(tid);
xhr1 = xhr2 = null;
render(foo);
render(bar);
}
}
function failure(e) {
xhr1 && xhr1.abort();
xhr1 = null;
xhr2 && xhr2.abort();
xhr2 = null;
console.log("read failed: " + e);
} ...tasks can be a lot simpler and cleaner. And unlike pre-emptive
threads, ContributingCurrently the best way to contribute is to hang out on IRC: the
channel is If you're looking for interesting things to work on, check out the issue tracker. |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论