task.js

Beautiful concurrency for JavaScript

  • 所有者: mozilla/task.js
  • 平台:
  • 許可證: Other
  • 分類:
  • 主題:
  • 喜歡:
    0
      比較:

Github星跟蹤圖

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, yield always makes it clear where tasks block.

Contributing

Currently the best way to contribute is to hang out on IRC: the
channel is #task.js on irc.mozilla.org. Or
you can always send me email (my Github nick at mozilla.com). And I'm
always happy to accept pull requests!

If you're looking for interesting things to work on, check out the
issue tracker.

主要指標

概覽
名稱與所有者mozilla/task.js
主編程語言JavaScript
編程語言JavaScript (語言數: 1)
平台
許可證Other
所有者活动
創建於2010-10-12 23:43:51
推送於2019-03-28 03:38:53
最后一次提交2013-11-27 23:37:13
發布數0
用户参与
星數1.6k
關注者數48
派生數73
提交數48
已啟用問題?
問題數37
打開的問題數24
拉請求數2
打開的拉請求數6
關閉的拉請求數3
项目设置
已啟用Wiki?
已存檔?
是復刻?
已鎖定?
是鏡像?
是私有?