@effect/cluster 0.49.3 → 0.49.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/Entity.ts CHANGED
@@ -7,13 +7,14 @@ import * as RpcGroup from "@effect/rpc/RpcGroup"
7
7
  import * as RpcServer from "@effect/rpc/RpcServer"
8
8
  import * as Arr from "effect/Array"
9
9
  import type { Brand } from "effect/Brand"
10
- import type * as Cause from "effect/Cause"
10
+ import * as Cause from "effect/Cause"
11
11
  import * as Context from "effect/Context"
12
12
  import * as Data from "effect/Data"
13
13
  import type { DurationInput } from "effect/Duration"
14
14
  import * as Effect from "effect/Effect"
15
15
  import * as Equal from "effect/Equal"
16
16
  import * as Exit from "effect/Exit"
17
+ import * as FiberId from "effect/FiberId"
17
18
  import { identity } from "effect/Function"
18
19
  import * as Hash from "effect/Hash"
19
20
  import * as Layer from "effect/Layer"
@@ -492,6 +493,18 @@ export class Request<Rpc extends Rpc.Any> extends Data.Class<
492
493
 
493
494
  const shardingTag = Context.GenericTag<Sharding, Sharding["Type"]>("@effect/cluster/Sharding")
494
495
 
496
+ /**
497
+ * @since 1.0.0
498
+ * @category Interruption
499
+ */
500
+ export const fiberIdIgnored = FiberId.make(-1, 0)
501
+
502
+ /**
503
+ * @since 1.0.0
504
+ * @category Interruption
505
+ */
506
+ export const interruptIgnored = Effect.failCause(Cause.interrupt(fiberIdIgnored))
507
+
495
508
  /**
496
509
  * @since 1.0.0
497
510
  * @category Testing
@@ -379,14 +379,15 @@ export const make = Effect.fnUntraced(function*(options?: {
379
379
  return SaveResultEncoded.Success()
380
380
  }
381
381
  const row = rows[0]
382
+ const replyKindNum = typeof row.reply_kind === "bigint" ? Number(row.reply_kind) : row.reply_kind
382
383
  return SaveResultEncoded.Duplicate({
383
384
  originalId: Snowflake.Snowflake(row.id as any),
384
385
  lastReceivedReply: row.reply_id ?
385
386
  Option.some({
386
387
  id: String(row.reply_id),
387
388
  requestId: String(row.id),
388
- _tag: row.reply_kind === replyKind.WithExit ? "WithExit" : "Chunk",
389
- ...(row.reply_kind === replyKind.WithExit
389
+ _tag: replyKindNum === replyKind.WithExit ? "WithExit" : "Chunk",
390
+ ...(replyKindNum === replyKind.WithExit
390
391
  ? { exit: JSON.parse(row.reply_payload as string) }
391
392
  : {
392
393
  sequence: Number(row.reply_sequence),
@@ -9,9 +9,12 @@ import type { DurationInput } from "effect/Duration"
9
9
  import * as Effect from "effect/Effect"
10
10
  import * as Equal from "effect/Equal"
11
11
  import * as Exit from "effect/Exit"
12
+ import * as FiberId from "effect/FiberId"
12
13
  import * as FiberRef from "effect/FiberRef"
13
14
  import { identity } from "effect/Function"
15
+ import * as Function from "effect/Function"
14
16
  import * as HashMap from "effect/HashMap"
17
+ import * as HashSet from "effect/HashSet"
15
18
  import * as Metric from "effect/Metric"
16
19
  import * as Option from "effect/Option"
17
20
  import * as Schedule from "effect/Schedule"
@@ -168,8 +171,10 @@ export const make = Effect.fnUntraced(function*<
168
171
  if (
169
172
  storageEnabled &&
170
173
  Context.get(request.rpc.annotations, Persisted) &&
174
+ Exit.isFailure(response.exit) &&
171
175
  Exit.isInterrupted(response.exit) &&
172
- (isShuttingDown || Context.get(request.rpc.annotations, Uninterruptible))
176
+ (isShuttingDown || Context.get(request.rpc.annotations, Uninterruptible) ||
177
+ isInterruptIgnore(response.exit.cause))
173
178
  ) {
174
179
  return options.storage.unregisterReplyHandler(request.message.envelope.requestId)
175
180
  }
@@ -543,3 +548,17 @@ const retryRespond = <A, E, R>(times: number, effect: Effect.Effect<A, E, R>): E
543
548
  times === 0 ?
544
549
  effect :
545
550
  Effect.catchAll(effect, () => Effect.delay(retryRespond(times - 1, effect), 200))
551
+
552
+ const IsInterruptedIgnoreReducer: Cause.CauseReducer<unknown, unknown, boolean> = {
553
+ emptyCase: Function.constFalse,
554
+ failCase: Function.constFalse,
555
+ dieCase: Function.constFalse,
556
+ interruptCase: (_, fiberId) => HashSet.has(FiberId.ids(fiberId), -1),
557
+ sequentialCase: (_, left, right) => left || right,
558
+ parallelCase: (_, left, right) => left || right
559
+ }
560
+
561
+ const isInterruptIgnore: (self: Cause.Cause<unknown>) => boolean = Cause.reduceWithContext(
562
+ undefined,
563
+ IsInterruptedIgnoreReducer
564
+ )