Remix.run Logo
whoisthemachine 3 days ago

> Your Child Loves Actor Frameworks

It turns out, Promises are actors. Very simple actors that can have one and only one message that upon resolution they dispatch to all other subscribed actors [0]. So children might love Promises and async/await then?

Personally, I've often thought the resolution to the "color" debate would be for a new language to make all public interfaces between modules "Promises" by default. Then the default assumption is "if I call this public function it could take some time to complete". Everything acting synchronously should be an implementation detail that is nice if it works out.

https://en.wikipedia.org/wiki/Futures_and_promises#Semantics...

emadda 3 days ago | parent | next [-]

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.

marcosdumay 2 days ago | parent | prev [-]

> Personally, I've often thought the resolution to the "color" debate would be for a new language to make all public interfaces between modules "Promises" by default.

Works well on Haskell. You can even remove that "public" and "between modules".