| 424 | lock.withPermit(Effect.suspend(() => pulls === seen ? pullUpstream : Effect.void)) |
| 425 | |
| 426 | const run = <A, D>(f: () => A | undefined | typeof NeedInput, end: () => D): Pull.Pull<A, ZipError | IE, D> => |
| 427 | Effect.suspend(function loop(): Pull.Pull<A, ZipError | IE, D> { |
| 428 | const seen = pulls |
| 429 | let result: A | undefined | typeof NeedInput |
| 430 | try { |
| 431 | result = f() |
| 432 | } catch (error) { |
| 433 | return isZipError(error) ? Effect.fail(error) : Effect.die(error) |
| 434 | } |
| 435 | if (result === NeedInput) return Effect.flatMap(pullInput(seen), loop) |
| 436 | return result === undefined ? Cause.done(end()) : Effect.succeed(result) |
| 437 | }) |
| 438 | |
| 439 | const body = (id: number): Stream.Stream<Uint8Array, ZipError | IE> => |
| 440 | Stream.fromPull(Effect.succeed(run(() => decoder.read(id), () => undefined))) |