To get a better understanding, I tried to get promise-simple in jsfiddle.
My idea was to use something like this.
console.log(new Date());
function t(d) {
var pd = Promise.defer();
setTimeout(function() {pd.resolve("first" + d);}, d*1000);
return pd;
};
Promise.when(t(1),t(2)).then(function(results) {console.log(new Date(),results);});
In this example function in then is called after having finished t(1) and t(2).
In log you can see delay of 2 secs for the slower function.
To get this running, I had to remove .resolve() for isPromise-part in when function. This problem exists in all sources and examples I found in github.
Therefore I'm unsure whether this is a correct solution. At least it does what I expect to do.
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
To get a better understanding, I tried to get promise-simple in jsfiddle.
My idea was to use something like this.
In this example function in then is called after having finished t(1) and t(2).
In log you can see delay of 2 secs for the slower function.
To get this running, I had to remove .resolve() for isPromise-part in when function. This problem exists in all sources and examples I found in github.
Therefore I'm unsure whether this is a correct solution. At least it does what I expect to do.