| 3128 | readonly shutdown?: boolean | undefined |
| 3129 | }): Stream.Stream<A> |
| 3130 | } = (pubsub, options): any => { |
| 3131 | const maxChunkSize = options?.maxChunkSize ?? DefaultChunkSize |
| 3132 | |
| 3133 | if (options?.scoped) { |
| 3134 | const effect = Effect.map( |
| 3135 | PubSub.subscribe(pubsub), |
| 3136 | (queue) => fromQueue(queue, { maxChunkSize, shutdown: true }) |
| 3137 | ) |
| 3138 | |
| 3139 | return options.shutdown ? Effect.map(effect, ensuring(PubSub.shutdown(pubsub))) : effect |
| 3140 | } |
| 3141 | const stream = flatMap( |
| 3142 | scoped(PubSub.subscribe(pubsub)), |
| 3143 | (queue) => fromQueue(queue, { maxChunkSize }) |
| 3144 | ) |
| 3145 | return options?.shutdown ? ensuring(stream, PubSub.shutdown(pubsub)) : stream |
| 3146 | } |
| 3147 | |
| 3148 | /** @internal */ |
| 3149 | export const fromTPubSub = <A>(pubsub: TPubSub.TPubSub<A>): Stream.Stream<A> => { |