Tasker - Task synchronizer - kind of a 'purposed' Promise #360
Replies: 3 comments
-
Posted at 2015-01-21 by @allObjects Tasker example with 5 taks 0..4, where task 1 and 3 fail (emulated) twice and once and succeed in 3rd and 2nd try, respectively.
The console output reads as follows:
|
Beta Was this translation helpful? Give feedback.
-
Posted at 2015-04-16 by JumJum There was another option for async handling |
Beta Was this translation helpful? Give feedback.
-
Posted at 2015-04-18 by @allObjects I've seen your conversation about Promise. For me it was missing the support of re-try options, that's why I went on my own - and I did not need (so far) the other stuff - which of course my solution is missing: the next or goto. Sequencing I can make after a sync point with (the first) 'parallels' and then venture into the next ones the same way as I did into the very first one. I used a pattern I got known to in 86 when working on TANDEM NonStop Systems(R) - now server division of HP - and worked on code generators to take advantage of fault tolerance and parallel execution. Tandem was not a hardware based fault tolerance - like [IBM S/88'(http://domino.research.ibm.com/tchjr/journalindex.nsf/600cc5649e2871db852568150060213c/cfc96f12d1fb70c385256bfa00685bd8!OpenDocument) and many others were/are - but more so on a software fault tolerance that allowed sync points in the application and not only in the system software (or hardwired in hardware / on the board). |
Beta Was this translation helpful? Give feedback.
-
Posted at 2015-01-21 by @allObjects
With almost almost all setup type of functions asking for a callback when done, such as connect(), Tasker is a helpful tool to fire off what ever (asynchronous) tasks that have to complete successfully before moving on or - on completion with error(s) - take other actions.
It is related to contributions made by @alex in conversation about Javascript Promises?
and [EDIT] @jumjum in conversation about Async handling.
Taskser's main built-in features are:
Initially, I had even a fatter version supporting (optional) extended logging, names for Tasker instances, names for the tasks, additional statistics about start time, end time, execution/elapsed time, and task results with passing them to the ok and err callbacks.
The fat version included also a part callback function invoked on successful or failed completion of each individual task to take additional action.
Dropping tries information, logging, and passing these things to the callbacks makes this implementation even lighter.
I'm using it as a module for simplifying synchronization of my setup tasks. Use is though not limited to just that. Anywhere in the app where a set of things have to happen before process flow can continue, a new Tasker can be instantiated. Taskers are fully reentrant and can be nested/cascaded/chained...
Setup of tasks can be inline in the Tasker constructor as anonymous functions or upfront as globally or locally scoped variables.
Skeletal task definition looks like this:
Note: trie is for reserved word try ;-)
For the ok and err setup see next post with example of 5 tasks.
Invocation of the Tasker looks like this:
*Tasker code (with some doc):
EDIT (at the time of version 1v94 (2017-08-29))
Feel free to continue reading in this conversation about Tasker... it will make you just more appreciate what happened here:
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.
All reactions