▲ | emadda 3 days ago | |
That's a nice mental model for promises. But it is not always true that one promise instance can be awaited in multiple places. In Swift you cannot get the ref to the Promise instance, so you cannot store it or await it at multiple places. Once you start an async fn the compiler forces you to await it where it was started (you can use `await task.value`, but that is a getter fn that creates a new hidden promise ref on every call). | ||
▲ | manmal 2 days ago | parent | next [-] | |
If I understand the use case correctly, then, in Swift, Tasks provide exactly what you have described. You can use the Task object in multiple places to await the result. | ||
▲ | whoisthemachine 3 days ago | parent | prev [-] | |
I'm not familiar with Swift, but it still sounds like it's describing an actor model, just one with a subset of the functionality. |