heph icon indicating copy to clipboard operation
heph copied to clipboard

Improve usability of the Spawn trait

Open Thomasdezeeuw opened this issue 3 years ago • 2 comments

In commit c33ed02ac860ecf0c0e3ccf16c9caefd1ae29b70 (issue #279) a new Spawn trait was introduced. It comes with three generic parameters S (Supervisor), NA (NewActor) and RT (either ThreadLocal or ThreadSafe). This was required because spawn of thread-safe actors requires, S, NA and NA::Actor to be Send + Sync, while thread-local actors don't have this requirement. However when using async function as actor we can't name NA or NA::Actor, making this trait impossible to use with it.

My initial idea was to split the two traits: Spawn and SpawnLocal, but types like TcpServer need a single trait otherwise we have to implement that twice as well.

Thomasdezeeuw avatar Oct 22 '20 08:10 Thomasdezeeuw

Some context: Spawn should be able to be used in functions that start actors. For example:

fn start_my_actor<S>(spawn: S)
where
    S: Spawn<MySupervisor, MyActor, ThreadLocal>
{
    // ...
}

The problem here is that MyActor for asynchronous function can't be named. MySupervisor is also a bit hard when using a regular function.

Thomasdezeeuw avatar Mar 02 '21 14:03 Thomasdezeeuw

In pr #433 I reviewed the trait again, but I didn't see any to move the S and NA parameters to the methods. Punting this until after the first release.

Thomasdezeeuw avatar Mar 26 '21 13:03 Thomasdezeeuw