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

Feedback for “Resource Management” #253

Open
DomiR opened this issue Aug 16, 2023 · 0 comments
Open

Feedback for “Resource Management” #253

DomiR opened this issue Aug 16, 2023 · 0 comments

Comments

@DomiR
Copy link

DomiR commented Aug 16, 2023

Would be nice to get an example with shared/concurrent access to resources.

Im coming from rxjs, where one can create a shared observable source which refcounts (e.g. wrapped event emitter).

// this will subscribe to an eventemitter, then share a subject which refcounts 
// it will setup and tear down the eventemitter subscription depending on how many subscriptions are open
const sharedSource = fromEvent(eventEmitter, 'changes').pipe(share())

// this will setup event emitter subscription
const sub1 = sharedSource.subscribe(e => {})
// this will join the subscription and consume the same events
const sub2 = sharedSource.subscribe(e => {});
// this will NOT clean up emitter subscription, as sub2 is still running
sub1.unsubscribe()
// this will tear down emitter subscription as nobody is subscribed anymore
sub2.unsubscribe()

So I'd like to consume a resource in multiple places at the same time especially with a longer-lived data types like a queue or a stream. I'm thinking of an injectable Effect service layer that provides a Stream (from Effect) or a Queue of events. I've watched this video https://www.youtube.com/watch?v=8B6YAax5Tes but it's outdated. If I were to have a file watcher service which different parts of the applogic subscribe to the file changes that would be a good example.

I guess it could be done manually by returning multiple copies of a stream or maybe I would need to rewire my brain first to not think of the solution in rxjs ways.

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

1 participant