4 ms·
You may not realize it but you're just rewriting hooks here. The example you give is too simple to show the problems with your initial approach. The main one is
by jolux 5y ago
You may not realize it but you're just rewriting hooks here. The example you give is too simple to show the problems with your initial approach. The main one is that if you're not extremely careful about when you're writing and when you're subscribing, you're going to end up with a race condition. Similar problems if you call "subscribe" in the wrong place. This is not a safe solution to the problem, and it does not circumvent the need for rules about usage.
- recursive 5y agoI'm sure there are complexities that I hadn't considered yet, but I don't see how a race condition can be one of them. Outside of workers, there's really no way to simultaneous concurrency in js. Order of dispatch to subscribers seems like it create similar problems, although it would be fully deterministic, rather than a race. Anyway, thanks for your insight.
- jolux 5y ago> Outside of workers, there's really no way to simultaneous concurrency in js. You're largely right but this part is mostly wrong in practice because of async. You can create race-like conditions very easily with promises/async if you're not careful. > Order of dispatch to subscribers seems like it create similar problems, although it would be fully deterministic, rather than a race. Yes, that's closer to what I meant. Not a data race, but you could end up in a loop.