3 ms·
Incremental computation can be useful for better responsiveness even if you only have one thread. A simple example in JavaScript would be a Mandelbrot viewer, w
by skybrian 8y ago
Incremental computation can be useful for better responsiveness even if you only have one thread. A simple example in JavaScript would be a Mandelbrot viewer, where you don't want to lock up the UI doing a heavy computation. So, you could have something that looks like an async call that really does the heavy computation in small chunks using idle callbacks, and the future completes when it'd done. (Using a background worker thread is probably better though.)
The async call itself doesn't return intermediate results, though, so you'd have to handle that a different way. And if you want to cancel the task, you need another way to handle that too.
Something like computing the digits of pi would be better represented by a stream or iterator since the caller should decide when it's done.
- jacquesm 8y agoThe correct way to deal with that problem is to decouple the UI from the computation, once process for each would be the ideal, anything less is going to messy and require all kinds of hacks to give the same outward appearance. Better still: one supervisor process and one for UI and computation each.
- skybrian 8y agoWell, in a web app you don't get to make those choices, but you could use a web worker.
- amelius 8y agoThat's called cooperative multitasking, and it was roughly how things worked in the Windows 3.1 era. Nowadays it's much better to use real threads, as they much better protect against latency (responsiveness) issues.
- markdog12 8y agoConcrete example right on the Dart homepage: https://www.dartlang.org/ https://www.dartlang.org/