const handler = (msg: string) => Effect.logInfo(msg)
const stream = (emitter: EventEmitter) =>
Stream.async<string>((emit) => {
emitter.on("event", async (msg: string) => {
await emit(Effect.succeed(Chunk.of(msg)))
})
}).pipe(Stream.runForEach(handler))
const program = Effect.gen(function*() {
const emitter = new EventEmitter()
const fiber = yield* Effect.fork(stream(emitter))
// Do other things with emitter
yield* Fiber.join(fiber)
})
const handler = (msg: string) => Effect.logInfo(msg)
const stream = (emitter: EventEmitter) =>
Stream.async<string>((emit) => {
emitter.on("event", async (msg: string) => {
await emit(Effect.succeed(Chunk.of(msg)))
})
}).pipe(Stream.runForEach(handler))
const program = Effect.gen(function*() {
const emitter = new EventEmitter()
const fiber = yield* Effect.fork(stream(emitter))
// Do other things with emitter
yield* Fiber.join(fiber)
})