Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ertrzyiks/futurejs
Dart Future and Completer features ported to javascript.
https://github.com/ertrzyiks/futurejs
Last synced: about 2 months ago
JSON representation
Dart Future and Completer features ported to javascript.
- Host: GitHub
- URL: https://github.com/ertrzyiks/futurejs
- Owner: ertrzyiks
- License: mit
- Created: 2013-12-22T19:44:48.000Z (about 11 years ago)
- Default Branch: master
- Last Pushed: 2014-01-17T19:51:45.000Z (about 11 years ago)
- Last Synced: 2024-12-07T19:35:56.283Z (about 2 months ago)
- Language: JavaScript
- Homepage:
- Size: 344 KB
- Stars: 2
- Watchers: 4
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Future.js
========Dart Future and Completer feature ported to javascript for NodeJS and browser.
See Dart API reference:
* [Completer](https://api.dartlang.org/docs/channels/stable/latest/dart_async/Completer.html)
* [Future](https://api.dartlang.org/docs/channels/stable/latest/dart_async/Future.html)and compare with [API docs](http://ertrzyiks.github.io/futurejs/docs/) of this library.
Features
-----#### Apply to callback architecture
Completer allows you to change callbacks schema into Future flow.
````javascript
/**
* Example 1
*
* Change callbacks based API into Future based
*/
function asyncTask(){
var completer = new Completer();task.on('success', function( data ){
completer.complete(data);
});
task.on('error', function( e ){
completer.completeError(e);
});
return completer.future;
}
````#### Future chaining
With Futures you can process async task with friendly interface. No more difficult to trace callbacks tree.
````javascript
/**
* Example 2
*
* Load list of items and update header text.
*/
function loadData(){
return asyncTask().then( function( rows ){
//render table
});
}loadData().then( function( rows ){
header1.text = "Loaded " + rows.length + " rows";
});````
#### Data processing
It provide comfortable way to split processing of complex data.
````javascript
/**
* Example 3
*
* Load list of items and update header text using Future data chaining.
*/
function loadData(){
return asyncTask().then( function( rows ){
//render table
return rows.length;
});
}loadData().then( function( rowsNum ){
header1.text = "Loaded " + rowsNum + " rows";
});````
TODO
---
- Future.delayed() function
- clean callbacks array after completion