-
• #2
Thanks for posting!
Calling
next()
only seems to work if apply is defined in the global context (not in a module) becausethis.next = function()....
defines the function next at the global level, correct?And that makes it impossible to nest async's, right?
-
• #3
I tried to nest asyncs some time ago, and failed :-(
This wasn't important that time, at least for me.
Anyway, now I have the explanation. -
• #4
It's nice to see the job getting done... for the price of 5 globals... not bad.
Reduce the 5 to 1 in the spirit of object-orientation helps with clean-up and passing the one as parm to the sequence defining application functions (async1..4) would conribute to hardening.
I liked the naming in Kazimir's original post: queue... and that it is: queing of sets of asynch operations that have to complete one after the other before a next set is allowed to be entered, and finally chaining these sets.
In some of my implementatins I needed result-dependent follow-up async operation(s) to be completed before the next set could be entered, and therefore allowed an insertion into or append to the funcs array. The effect is similar to a pseudo-multi-level / quasi-context creation (easy to implement by enhancing the next() to accept optionally the required parameters to do it).
Surfing the subject shows many implementations with various focus.
@JumJum, what is the
obj
's purpose in line 46? Espruino is reporting it undefined... -
• #5
Mhh, I have to read Kazimir's original post...
Promises are a powerful tool to avoid callback-hell.
For Espruino I was searching for a tiny solution and found 7 Lines from Krasimir.
Based on this I wrote a simple flow solution.
It supports
Handling is simple as you can see here: