Javascript Promises? #4342
Replies: 1 comment
-
Posted at 2014-12-11 by @gfwilliams Hi Alex, Someone else asked this a while back. Basically Promises don't have to be part of the JavaScript interpreter - I haven't tried it, but there's a smallish promises implementation right here that you should be able to use (although it might need some changes for it to be usable with I'd be happy to include a library if someone contributed one, but I'm not sure it's worth including in the Espruino interpreter given it can just be pulled in if needed. Posted at 2014-12-11 by favo I've adjusted a promise module for Espruino a while ago, you can have look at it here: This is how it works: It's maybe not be perfectly optimized for Espruino for now, but I'm using it in different JS based projects for a while now and its doing what its meant to do :) Posted at 2014-12-12 by @gfwilliams @favo thanks! Would you mind if I put that into a module for Espruino? It'd make it easier for @alex to use (how do you tend to use that module yourself? Using the 'Projects' option, or linking to the URL?). Did you base the module on something else, and do you know what the original license was? If it did get included I don't want to violate anyone's copyright. Posted at 2014-12-18 by Alex Hi, so far I've been using this with node: It's MIT licensed and very good! Posted at 2014-12-19 by favo @gfwilliams, you are welcome to use it. It is based on https://github.com/iskugor/js-promise-simple/ and was not put under a specific license. There are a lot of adaptions of the simple promises out there. I've put my modules in the default Posted at 2014-12-27 by JumJum To get a better understanding, I tried to get promise-simple in jsfiddle.
In this example function in then is called after having finished t(1) and t(2). Posted at 2015-01-21 by @allObjects For an alternative and dedicated variation, take a look at Tasker - Task synchronizer - kind of a 'purposed' Promise. EDIT (at the time of version 1v94 (2017-08-29)) Version 1v86 (2016-07-05) introduced Promise and Promise has matured thru version [1v91 (2017-01-12)] (http://forum.espruino.com/conversations/298540/). Promise makes life of synchronizing/sequencing of asynchronous tasks/callback of callbacks of callbacks of... much much easier... Promise is practically the only way out of callback-hell. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2014-12-11 by Alex
Hi All,
Would it be possible to have JavaScript Promises in the API for async stuff?
Cheers!
Beta Was this translation helpful? Give feedback.
All reactions