Effect CommunityEC
Effect Community16mo ago
2 replies
David Golightly

Stream onStart behavior

Playground link: https://effect.website/play#327266c625eb

I would naively expect Stream.onStart to call its effect after the stream is initialized (and the event listeners are registered), but it doesn't appear to be the case. In my scenario, my stream relies heavily on event emitters, and I want to execute a "post-initialization" effect which emits events, but only after the event listeners are registered. Is there a better alternative? I have been getting around this by doing:

Stream.asyncEffect<T>((emit) => Effect.gen(function* () {
  // ... subscribe to events
  yield* initialize
})).pipe(
  ...
)


but was just curious if there's a better way? thanks again!
Try Effect in your browser and share your code!
Effect Playground
Was this page helpful?