| 383 | lock.withPermit(Effect.suspend(() => pulls === seen ? pullUpstream : Effect.void)) |
| 384 | |
| 385 | const run = <A, D>(f: () => A | undefined | typeof NeedInput, end: () => D): Pull.Pull<A, TarError | IE, D> => |
| 386 | Effect.suspend(function loop(): Pull.Pull<A, TarError | IE, D> { |
| 387 | const seen = pulls |
| 388 | let result: A | undefined | typeof NeedInput |
| 389 | try { |
| 390 | result = f() |
| 391 | } catch (error) { |
| 392 | return isTarError(error) ? Effect.fail(error) : Effect.die(error) |
| 393 | } |
| 394 | if (result === NeedInput) return Effect.flatMap(pullInput(seen), loop) |
| 395 | return result === undefined ? Cause.done(end()) : Effect.succeed(result) |
| 396 | }) |
| 397 | |
| 398 | const body = (id: number): Stream.Stream<Uint8Array, TarError | IE> => |
| 399 | Stream.fromPull(Effect.succeed(run(() => decoder.read(id), () => undefined))) |