6 ms·
The difference is that you can look at function, see it takes no nurseries as parameters, and know it does not spawn any background tasks. And if it does take n
by scott_s 9y ago
The difference is that you can look at function, see it takes no nurseries as parameters, and know it does not spawn any background tasks. And if it does take nurseries, then you know it's likely that it does.
- jeremiep 9y agoWhats the difference between taking a nursery and returning a promise? Both put the context in the signature, but the later is actually composable.
- scott_s 9y agoWhen I call a function, I have no way of knowing if there are any unhandled promises within it. The difference is the restriction: with nurseries, background tasks can only outlive function calls if the calling function allows them to.
- jeremiep 9y agoI get compile-time warnings or runtime errors when I create unhandled promises. What more is needed?
- scott_s 9y agoNeeded is a strong word, but what this provides are guarantees when reading the code. Much like you know that control flow will come back to the function you're reading after calling another function. We didn't need to know that control flow will resume in the calling function, but it turned out to be very useful.
- jeremiep 9y agoWhat guarantees? Nothing prevents a function receiving a nursery from not using it. Unless the language can enforce it you don't really gain anything valuable over returning a Promise, except more complex code that doesn't compose. > Much like you know that control flow will come back to the function you're reading after calling another function. What about continuations? Exceptions? Aborts? setjmp()? I can think of many cases where control doesn't return to the caller that are perfectly valid. Basically, either the code is so simple theres obviously no bugs, or the code is so complex theres no obvious bugs. I feel a nursery is closer to the later than the former.
- yoz-y 9y agoCan you force explicit nursery passing though? One might make a global nursery object and then just rely on that.