* Resolves an SSESource to a reader, reporting whether this call * acquired the lock (and is therefore responsible for releasing it).
(source: SSESource)
| 87 | * acquired the lock (and is therefore responsible for releasing it). |
| 88 | */ |
| 89 | function toReader(source: SSESource): { |
| 90 | reader: ReadableStreamDefaultReader<Uint8Array> |
| 91 | ownsLock: boolean |
| 92 | } { |
| 93 | if (source instanceof ReadableStream) { |
| 94 | return { reader: source.getReader(), ownsLock: true } |
| 95 | } |
| 96 | if (source instanceof Response) { |
| 97 | if (!source.body) throw new Error('No response body') |
| 98 | return { reader: source.body.getReader(), ownsLock: true } |
| 99 | } |
| 100 | return { reader: source, ownsLock: false } |
| 101 | } |
| 102 | |
| 103 | /** |
| 104 | * Strips an optional trailing carriage return from a single SSE line, so both |