mirror of
https://github.com/Effect-TS/effect.git
synced 2026-12-02 03:15:52 +08:00
change fiberId type from Option<number> to number | undefined (#412)
This commit is contained in:
@@ -40,7 +40,6 @@
|
||||
* @since 2.0.0
|
||||
*/
|
||||
import type * as Filter from "./data/Filter.ts"
|
||||
import type { Option } from "./data/Option.ts"
|
||||
import type * as Effect from "./Effect.ts"
|
||||
import type { Equal } from "./interfaces/Equal.ts"
|
||||
import type { Inspectable } from "./interfaces/Inspectable.ts"
|
||||
@@ -338,13 +337,12 @@ export interface Fail<out E> extends Cause.FailureProto<"Fail"> {
|
||||
* @example
|
||||
* ```ts
|
||||
* import { Cause } from "effect"
|
||||
import * as Option from "effect/data/Option"
|
||||
*
|
||||
* const cause = Cause.interrupt(123)
|
||||
* const failure = cause.failures[0]
|
||||
* if (Cause.failureIsInterrupt(failure)) {
|
||||
* console.log(failure._tag) // "Interrupt"
|
||||
* console.log(Option.isSome(failure.fiberId)) // true
|
||||
* console.log(failure.fiberId !== undefined) // true
|
||||
* }
|
||||
* ```
|
||||
*
|
||||
@@ -352,7 +350,7 @@ import * as Option from "effect/data/Option"
|
||||
* @category models
|
||||
*/
|
||||
export interface Interrupt extends Cause.FailureProto<"Interrupt"> {
|
||||
readonly fiberId: Option<number> // TODO: why not `number | undefined`?
|
||||
readonly fiberId: number | undefined
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -79,9 +79,9 @@ import { version } from "./version.ts"
|
||||
|
||||
/** @internal */
|
||||
export class Interrupt extends FailureBase<"Interrupt"> implements Cause.Interrupt {
|
||||
readonly fiberId: Option.Option<number>
|
||||
readonly fiberId: number | undefined
|
||||
constructor(
|
||||
fiberId: Option.Option<number>,
|
||||
fiberId: number | undefined,
|
||||
annotations = new Map<string, unknown>()
|
||||
) {
|
||||
super("Interrupt", annotations, "Interrupted")
|
||||
@@ -120,13 +120,12 @@ export class Interrupt extends FailureBase<"Interrupt"> implements Cause.Interru
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
export const failureInterrupt = (fiberId?: number | undefined): Cause.Interrupt =>
|
||||
new Interrupt(Option.fromNullable(fiberId))
|
||||
export const failureInterrupt = (fiberId?: number | undefined): Cause.Interrupt => new Interrupt(fiberId)
|
||||
|
||||
/** @internal */
|
||||
export const causeInterrupt = (
|
||||
fiberId?: number | undefined
|
||||
): Cause.Cause<never> => new CauseImpl([new Interrupt(Option.fromNullable(fiberId))])
|
||||
): Cause.Cause<never> => new CauseImpl([new Interrupt(fiberId)])
|
||||
|
||||
/** @internal */
|
||||
export const causeHasFail = <E>(self: Cause.Cause<E>): boolean => self.failures.some(failureIsFail)
|
||||
@@ -174,8 +173,8 @@ export const causeFilterInterruptors = <E>(self: Cause.Cause<E>): Set<number> |
|
||||
const f = self.failures[i]
|
||||
if (f._tag !== "Interrupt") continue
|
||||
interruptors ??= new Set()
|
||||
if (f.fiberId._tag === "Some") {
|
||||
interruptors.add(f.fiberId.value)
|
||||
if (f.fiberId !== undefined) {
|
||||
interruptors.add(f.fiberId)
|
||||
}
|
||||
}
|
||||
return interruptors ? interruptors : Filter.fail(self)
|
||||
@@ -370,7 +369,7 @@ const cleanErrorStack = (
|
||||
const interruptCauseStack = (error: Error, interrupts: Array<Cause.Interrupt>): string => {
|
||||
const out: Array<string> = [`${error.name}: ${error.message}`]
|
||||
for (const current of interrupts) {
|
||||
const fiberId = current.fiberId._tag === "Some" ? `#${current.fiberId.value}` : "unknown"
|
||||
const fiberId = current.fiberId !== undefined ? `#${current.fiberId}` : "unknown"
|
||||
const span = current.annotations.get(InterruptorSpanKey.key) as Tracer.Span | undefined
|
||||
out.push(` at fiber (${fiberId})`)
|
||||
if (span) pushSpanStack(out, span)
|
||||
|
||||
@@ -3365,7 +3365,7 @@ export function CauseFailure<E extends Top, D extends Top>(error: E, defect: D):
|
||||
Union([
|
||||
TaggedStruct("Fail", { error }),
|
||||
TaggedStruct("Die", { defect }),
|
||||
TaggedStruct("Interrupt", { fiberId: UndefinedOr(Finite) }) // TODO: UndefinedOr(Int)?
|
||||
TaggedStruct("Interrupt", { fiberId: UndefinedOr(Finite) })
|
||||
]),
|
||||
Transformation.transform({
|
||||
decode: (input) => {
|
||||
@@ -3378,16 +3378,7 @@ export function CauseFailure<E extends Top, D extends Top>(error: E, defect: D):
|
||||
return Cause_.failureInterrupt(input.fiberId)
|
||||
}
|
||||
},
|
||||
encode: (failure) => {
|
||||
switch (failure._tag) {
|
||||
case "Fail":
|
||||
return { _tag: "Fail", error: failure.error } as const
|
||||
case "Die":
|
||||
return { _tag: "Die", defect: failure.defect } as const
|
||||
case "Interrupt":
|
||||
return { _tag: "Interrupt", fiberId: O.getOrUndefined(failure.fiberId) } as const
|
||||
}
|
||||
}
|
||||
encode: identity
|
||||
})
|
||||
),
|
||||
arbitrary: {
|
||||
|
||||
@@ -151,7 +151,7 @@ export const causeResponse = <E>(
|
||||
}
|
||||
case "Interrupt": {
|
||||
if (acc[1].length > 0) return acc
|
||||
const response = f.fiberId._tag === "Some" && f.fiberId.value === clientAbortFiberId
|
||||
const response = f.fiberId === clientAbortFiberId
|
||||
? clientAbortError
|
||||
: serverAbortError
|
||||
return [Effect.succeed(response), [f]]
|
||||
|
||||
Reference in New Issue
Block a user