3 ms·
If you want job1 and job2 to be executed in parallel, you could do this: set result to [job1(), job2()] set result1 to the first result set result2 to th
by recursivedoubts 2y ago
If you want job1 and job2 to be executed in parallel, you could do this:
set result to [job1(), job2()]
set result1 to the first result
set result2 to the last result
The array expression will wait until all promise values resolve.
This isn't really what hyperscript is designed for, however: its async behavior is designed instead to take the async/sync distinction (and callback hell) out of "normal" DOM scripting. If you have sophisticated async needs then JavaScript is probably a better option. The good news is that hyperscript can call JavaScript functionality in the normal way, so that is an easy option if hyperscripts behavior isn't sufficient for your needs.
- paldepind2 2y agoThanks for the reply. I can understand that the purpose here isn't to be as powerful as JavaScript, but rather to be simpler and easier. That being said, is there a way to achieve the below or is that beyond the limits? const result = Promise.race(job1(), job2());
- recursivedoubts 2y agoYou can't achieve that with the intended semantics directly in hyperscript, because it will resolve all argument promises before invoking Promise.race() You could move that out to JavaScript and then call that function from hyperscript: set result to jsPromiseRace() it could also be done as inline js: js return Promise.race(job1(), job2()); end log the result but I think if you are writing this style of code it makes more sense to just kick out to JavaScript for it.