Promises/A+ library “Ten.Promise” 0.1.0 Released
We released the first version of Ten.Promise on 6 February 2013.
What is Ten.Promise?
Ten.Promise is a JavaScript Promises/A+ library written in TypeScript. Using this library, you can make asynchronous (or async) patterns easier. See following page to know about Promises/A+.
As the Promises/A+ specification defines an interface of a promise object and how a promise object treats other promise object, Ten.Promise will work along with other Promises/A+ implementations well.
Downloads
Where Ten.Promise works
We made sure that Ten.Promise work on following JavaScript processing environment:
- Mozilla Firefox 19,
- Internet Explorer 6, 8, 10,
- Opera 12.13,
- Chrome 24,
- Node 0.8.
We couldn't check on other environments.
Our aim
We aim to let Ten.Promise be a Promises/A+ library having interface-level compatibility with following libraries:
- WinJS.Promise, and
- JSDeferred (except static methods).
Current status
Ten.Promise 0.1.0 passes all of the Promises/A+ tests (version 1.2.0).
And a part of a WinJS.Promise interface is implemented. Implemented constructor and methods are just shown below.
- WinJS.Promise constructor (Ten.Promise constructor)
- WinJS.Promise#then method (Ten.Promise#then method)
- WinJS.Promise#cancel method (Ten.Promise#cancel method)
Big difference between WinJS.Promise and Ten.Promise
These two libraries have difference in the timing of the call of callback functions which are registered with a promise object already fulfilled (or rejected) by its then
method:
- A promise object already fulfilled (or rejected) of WinJS.Promise calls a callback function just registered by
then
method before returning from the method; - A promise object already fulfilled (or rejected) of Ten.Promise return from
then
method before a callback function is called.
Ten.Promise is compliant to the Promises/A+ specification, while WinJS.Promise is not.
Example
<script src="Ten.Promise.js"></script> <script> // create promise object var p = new Ten.Promise(function (s,e,p) { var count = 0; var timerId; function timer() { setTimeout(function () { count++; if (count < 5) { p(count); timer(); } else { s(count); } }, 4000); } timer(); }); // register callback functions p.then( function onSuccess(val) { // it is called one time (value: 5) console.log("success callback: " + val); }, function onError(err) {}, // in this example, this will not be called function onProgress(val) { // it is called four times (respective values: 1, 2, 3, 4) console.log("progress callback: " + val); }); </script>