bee icon indicating copy to clipboard operation
bee copied to clipboard

Make worker communication more object-like

Open pvdrz opened this issue 2 years ago • 0 comments

Description

Put all the event-passing logic behind named methods for each worker handle.

As an example, instead of exposing this to the caller:

enum WorkerEvent {
     SendFoo(Foo),
     RequestBar(oneshot::Sender<Bar>),
}

worker_handle.send(WorkerEvent::SendFoo(foo))?;

let (tx, rx) = oneshot::channel();
worker_handle.send(WorkerEvent::RequestBar(tx))?;
let bar = rx.await?;

expose this:

worker_handle.send_foo(foo)?;

let bar = worker_handle.request_bar().await?;

Motivation

This would make inter-worker communication cleaner and more readable. It would also mean that the caller doesn't need to import any channel items to send events.

Requirements

Write a list of what you want this feature to do.

  1. Implement one method for each event variant available for each actor.
  2. Make the event type private.

Open questions

Should this methods be fallible?

We have to define how to handle message passing errors.

Are you planning to do it yourself in a pull request?

Yes.

pvdrz avatar Mar 25 '22 16:03 pvdrz