3 ms·
Promises can be helpful in a pure CPU bound workload as well: they help to avoid blocking the main thread, by yielding more often. This is typically done by bre
by hrjet 10y ago
Promises can be helpful in a pure CPU bound workload as well: they help to avoid blocking the main thread, by yielding more often. This is typically done by breaking a long running computation into a series of sub-computations that are scheduled on a timer, and the top level API returns a Promise that completes when all computations are over.
The same goal could also be achieved with multiple threads (webworkers for example). But the promises and async/await syntax is more convenient.