3 ms·
In javascript it would yes (actually a `yield*`, or an `await` in async/await). With native coroutines it wouldn't (the runtime would implicitly yield on IO).
by masklinn 11y ago
In javascript it would yes (actually a `yield*`, or an `await` in async/await). With native coroutines it wouldn't (the runtime would implicitly yield on IO).
> But what if I want the fetch() function to decide whether to yield or not?
In javascript? The question doesn't really make sense, a function is either sync or async.
- amelius 11y ago> The question doesn't really make sense, a function is either sync or async. Well, either fetch() blocks, or not. If it blocks, then it should yield, its caller should yield, etc. If it doesn't block, then it can just run to completion.
- masklinn 11y agoDon't elide important parts of the quote. In javascript your question doesn't make sense. > Well, either fetch() blocks, or not. Javascript functions always block. > If it blocks, then it should yield, its caller should yield, etc. If it doesn't block, then it can just run to completion. If a function is async, you must yield[0]. It may not need* that capability (conditionally) and doesn't have to yield at all e.g. function*() { return 4; } is valid and will not suspend. You must still yield*[0] on it so that it is properly resolved as a generator. [0] I think that's not an issue for async/await as it's syntactic sugar for then chains, the code itself may be converted to a generator or whatever but it will embed the driver