| 551 | }) |
| 552 | }), |
| 553 | saveReply(reply) { |
| 554 | const requestId = reply.reply.requestId |
| 555 | return Effect.flatMap(storage.saveReply(reply), () => { |
| 556 | const handlers = replyHandlers.get(requestId) |
| 557 | if (!handlers) { |
| 558 | return Effect.void |
| 559 | } else if (reply.reply._tag === "WithExit") { |
| 560 | replyHandlers.delete(requestId) |
| 561 | for (let i = 0; i < handlers.length; i++) { |
| 562 | const handler = handlers[i] |
| 563 | handler.shardSet.delete(handler) |
| 564 | handler.resume(Effect.void) |
| 565 | } |
| 566 | } |
| 567 | return handlers.length === 1 |
| 568 | ? handlers[0].respond(reply) |
| 569 | : Effect.forEach(handlers, (handler) => handler.respond(reply)) |
| 570 | }) |
| 571 | } |
| 572 | }) |
| 573 | }) |
| 574 | |