Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mozilla/task.js
Beautiful concurrency for JavaScript
https://github.com/mozilla/task.js
Last synced: about 1 month ago
JSON representation
Beautiful concurrency for JavaScript
- Host: GitHub
- URL: https://github.com/mozilla/task.js
- Owner: mozilla
- License: other
- Created: 2010-10-12T23:43:51.000Z (almost 14 years ago)
- Default Branch: master
- Last Pushed: 2019-03-28T03:38:53.000Z (over 5 years ago)
- Last Synced: 2024-04-14T16:01:23.401Z (5 months ago)
- Language: JavaScript
- Homepage: http://taskjs.org
- Size: 1.6 MB
- Stars: 1,632
- Watchers: 49
- Forks: 72
- Open Issues: 31
-
Metadata Files:
- Readme: README.md
- License: COPYING
Awesome Lists containing this project
README
# task.js
* *What?* Cooperative concurrency for [ES6](http://wiki.ecmascript.org/doku.php?id=harmony:proposals)
* *Why?* Who says JavaScript I/O has to be ugly?
* *Where?* [http://taskjs.org](http://taskjs.org)
* *When?* As soon as your JS engine supports [generators](http://wiki.ecmascript.org/doku.php?id=harmony:generators)!
* *How?* [http://taskjs.org](http://taskjs.org)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:
``` javascript
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:
``` javascript
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](http://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](task.js/issues)**.