4 ms·
It is not possible to fulfill promise more than once. Thus promisifying of window.setInterval() and window.requestAnimationFrame() is very questionable. The s
by c-smile 10y ago
It is not possible to fulfill promise more than once.
Thus promisifying of window.setInterval() and window.requestAnimationFrame() is very questionable.
The same applies to possibly repeatable .onXXXX() methods.
2.2.2 If onFulfilled is a function:
...
2.2.2.3 it must not be called more than once.
https://promisesaplus.com/ https://promisesaplus.com/
- foota 10y agorequestAnimationFrame doesn't repeat, it only triggers the function once, you have to request an animation frame on each render to have it run again. Valid point however regarding the other things. Might be a neat api to have like a generator for these kinds of things, something like: for click in window.document.body: // do something with click and then stick this in an async function?
- gianlucaguarini 10y agoSee my answer above :)
- throwanem 10y agoIt's not possible to fulfill a promise more than once, no. But a Promise.all method, while outside the A+ spec, conventionally returns a promise for the resolution of all promises in the array passed as an argument; if all those promises are fulfilled, so will be the promise returned by .all, while if any of them is rejected, so will be the etc., etc. So the browser example given in the Allora Github readme is perfectly reasonable. It's the exact same kind of thing you do when, for example, you need to await the completion of multiple separate HTTP requests in order to do something with all of their results. While, again, .all isn't part of the A+ standard, this is perfectly conventional and unremarkable behavior; not only is it unsurprising to see in a library like this one, it would be exceptional in its absence if it weren't there. That said, I would be curious to see Allora compared with, for example, Bluebird's "promisifyAll" method, which appears to do much the same thing.
- c-smile 10y agoSo what does this thatWindow.setInterval(100).then( foo ) mean exactly? How many times the foo() will be called? And how to stop that interval?
- gianlucaguarini 10y agofoo will be called only once (see my answer above). I am working on another script to achieve event streams using es6 generators let's keep in touch
- egeozcan 10y agopromisifiedWindow.setInterval(200).then(x => console.log("res:", x)); -> Promise {[[PromiseStatus]]: "pending", [[PromiseValue]]: undefined} >> VM310:1 res: undefined How do you cancel the interval?
- gianlucaguarini 10y agoAt moment it's not possible and it does not make any sense to use a setInterval with a promise in return. But I will think about a simple solution to clear the timer functions
- gianlucaguarini 10y agoOk with this it should be possible https://github.com/GianlucaGuarini/allora/pull/3 https://github.com/GianlucaGuarini/allora/pull/3
- gianlucaguarini 10y agoYes you are right, mine was just a proof of concept and it works properly for callbacks that must be triggered only once. I am working on another script to make an event streams api from native functions a bit like Bacon.js or fx.js already do but with less code