Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Actor & AsyncChannel instead of lock/serialize #12

Open
malhal opened this issue Dec 17, 2024 · 1 comment
Open

Actor & AsyncChannel instead of lock/serialize #12

malhal opened this issue Dec 17, 2024 · 1 comment

Comments

@malhal
Copy link
Contributor

malhal commented Dec 17, 2024

In ForkedResource I wondered if you considered using actor instead of lock with the serialize func?

Also how about AsyncChannel instead of the continuations array? AsyncChannel Is great way to communicate between tasks.

@drewmccormack
Copy link
Owner

drewmccormack commented Dec 17, 2024

The very first thing I considered was whether to make an actor, or just a Sendable class. The problem I had with an actor is it then forces everyone down the async/await path, and could even introduce more race conditions than it solves.

To me ForkedResource feels like a lower level thing, which you could use inside of your actors, rather than an actor itself.

I have an app that uses an actor for the Store, and I regret it deeply. Hope to replace it soon with this package. It is just riddled with uncertainties, because every suspension point is a potential race condition.

So my preference is definitely to stick with a Sendable class, which can be used even by people not adopting async/await. And if people want an actor, it is trivial to wrap a ForkedResource in an actor. (It might be an idea just to provide a ForkedActor type which is a simple wrapper around ForkedResource for those who want that.)

As for AsyncChannel, I am not that at home with it. I haven't used it before, and am not familiar.

I just "solved" the observation problem by allowing people to ask for a changeStream, and they can then put that in a for loop. The ForkedResource tracks the open streams, and messages each. If AsyncChannel is a better solution for this problem, I'm open to it.

@malhal malhal changed the title Actor instead of lock/serialize Actor & AsyncChannel instead of lock/serialize Dec 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants