by spankalee · 9y ago · 0 comments
* non-determinism -> order in which setTimeouts run
* race conditions -> callbacks happen in an unexpected order
* deadlock -> broken callback chain
Callbacks can only come back in an unexpected order if you are using I/O.
A broken callback chain is not the traditional definition of "deadlock".
Certainly, if they are issued from different callbacks. :-) And in relation to how they may happen to be interleaved with I/O.
Also add to the non-determinism bucket: the order in which messages arrive from separate Workers.
> Callbacks can only come back in an unexpected order if you are using I/O.
Which abounds and takes many forms both in the browser and node.js.
> A broken callback chain is not the traditional definition of "deadlock".
Indeed, but it is the same class of developer hazard at play: waiting for an event to happen than will never come. Admittedly, only a subset of dropped callback chains correspond to the strict definition of deadlock: those where a chain is involved in marking a state/resource as available.
For example: I ignore the next button press on a ui that disables the button pending a reply because I accidentally failed to update the button state when a network request failed.
That's non determinism from I/O, not from the callback or the setTimeout. setTimeouts are called in order based on schedule time.
And you can't blame non-determinism in JS on I/O. No language in existence is deterministic based on that measure.