(
this: Entity<string, Rpcs>,
build:
| ((
mailbox: Mailbox.ReadonlyMailbox<Envelope.Request<Rpcs>>,
replier: Replier<Rpcs>
) => Effect.Effect<never, never, R>)
| Effect.Effect<
(
mailbox: Mailbox.ReadonlyMailbox<Envelope.Request<Rpcs>>,
replier: Replier<Rpcs>
) => Effect.Effect<never, never, R>,
never,
RX
>,
options?: {
readonly maxIdleTime?: DurationInput | undefined
readonly mailboxCapacity?: number | "unbounded" | undefined
readonly disableFatalDefects?: boolean | undefined
readonly defectRetryPolicy?: Schedule.Schedule<any, unknown> | undefined
readonly spanAttributes?: Record<string, string> | undefined
}
)
| 273 | }, |
| 274 | of: identity, |
| 275 | toLayerMailbox< |
| 276 | Rpcs extends Rpc.Any, |
| 277 | R, |
| 278 | RX = never |
| 279 | >( |
| 280 | this: Entity<string, Rpcs>, |
| 281 | build: |
| 282 | | (( |
| 283 | mailbox: Mailbox.ReadonlyMailbox<Envelope.Request<Rpcs>>, |
| 284 | replier: Replier<Rpcs> |
| 285 | ) => Effect.Effect<never, never, R>) |
| 286 | | Effect.Effect< |
| 287 | ( |
| 288 | mailbox: Mailbox.ReadonlyMailbox<Envelope.Request<Rpcs>>, |
| 289 | replier: Replier<Rpcs> |
| 290 | ) => Effect.Effect<never, never, R>, |
| 291 | never, |
| 292 | RX |
| 293 | >, |
| 294 | options?: { |
| 295 | readonly maxIdleTime?: DurationInput | undefined |
| 296 | readonly mailboxCapacity?: number | "unbounded" | undefined |
| 297 | readonly disableFatalDefects?: boolean | undefined |
| 298 | readonly defectRetryPolicy?: Schedule.Schedule<any, unknown> | undefined |
| 299 | readonly spanAttributes?: Record<string, string> | undefined |
| 300 | } |
| 301 | ) { |
| 302 | const buildHandlers = Effect.gen(this, function*() { |
| 303 | const behaviour = Effect.isEffect(build) ? yield* build : build |
| 304 | const mailbox = yield* Mailbox.make<Envelope.Request<Rpcs>>() |
| 305 | |
| 306 | // create the rpc handlers for the entity |
| 307 | const handler = (envelope: any) => { |
| 308 | return Effect.async<any, any>((resume) => { |
| 309 | mailbox.unsafeOffer(envelope) |
| 310 | resumes.set(envelope, resume) |
| 311 | }) |
| 312 | } |
| 313 | const handlers: Record<string, any> = {} |
| 314 | for (const rpc of this.protocol.requests.keys()) { |
| 315 | handlers[rpc] = handler |
| 316 | } |
| 317 | |
| 318 | // make the Replier for the behaviour |
| 319 | const resumes = new Map<Envelope.Request<any>, (exit: Exit.Exit<any, any>) => void>() |
| 320 | const complete = (request: Envelope.Request<any>, exit: Exit.Exit<any, any>) => |
| 321 | Effect.sync(() => { |
| 322 | const resume = resumes.get(request) |
| 323 | if (resume) { |
| 324 | resumes.delete(request) |
| 325 | resume(exit) |
| 326 | } |
| 327 | }) |
| 328 | const replier: Replier<Rpcs> = { |
| 329 | succeed: (request, value) => complete(request, Exit.succeed(value)), |
| 330 | fail: (request, error) => complete(request, Exit.fail(error)), |
| 331 | failCause: (request, cause) => complete(request, Exit.failCause(cause)), |
| 332 | complete |
nothing calls this directly
no test coverage detected
searching dependent graphs…