From 2c52048f4bb11304819ddce5868f35590885498b Mon Sep 17 00:00:00 2001 From: Giulio Canti Date: Wed, 7 Feb 2024 08:50:02 +0100 Subject: [PATCH] =?UTF-8?q?change=20`Runtime.RunCallbackOptions`=20type=20?= =?UTF-8?q?parameters=20order=20from=20`RunCa=E2=80=A6=20(#2069)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .changeset/afraid-pumpkins-attack.md | 5 ++++ .changeset/brave-days-invite.md | 5 ++++ .changeset/fuzzy-lamps-live.md | 5 ++++ packages/effect/src/Effect.ts | 4 +-- packages/effect/src/Runtime.ts | 14 +++++----- packages/effect/src/Stream.ts | 2 +- packages/effect/src/internal/keyedPool.ts | 12 ++++----- packages/effect/src/internal/pool.ts | 26 +++++++++---------- packages/effect/src/internal/runtime.ts | 8 +++--- packages/effect/src/internal/sink.ts | 10 +++---- packages/effect/src/internal/stm/core.ts | 12 ++++----- packages/effect/src/internal/stm/stm.ts | 2 +- .../effect/src/internal/stm/stm/stmState.ts | 14 +++++----- .../effect/src/internal/stm/stm/tryCommit.ts | 6 ++--- packages/effect/src/internal/stream.ts | 13 +++++----- .../src/internal/stream/debounceState.ts | 8 +++--- 16 files changed, 80 insertions(+), 66 deletions(-) create mode 100644 .changeset/afraid-pumpkins-attack.md create mode 100644 .changeset/brave-days-invite.md create mode 100644 .changeset/fuzzy-lamps-live.md diff --git a/.changeset/afraid-pumpkins-attack.md b/.changeset/afraid-pumpkins-attack.md new file mode 100644 index 0000000000..1da97cc659 --- /dev/null +++ b/.changeset/afraid-pumpkins-attack.md @@ -0,0 +1,5 @@ +--- +"effect": minor +--- + +change `Runtime.AsyncFiberException` type parameters order from `AsyncFiberException` to `AsyncFiberException` diff --git a/.changeset/brave-days-invite.md b/.changeset/brave-days-invite.md new file mode 100644 index 0000000000..f87cabe0d3 --- /dev/null +++ b/.changeset/brave-days-invite.md @@ -0,0 +1,5 @@ +--- +"effect": minor +--- + +change `Runtime.Cancel` type parameters order from `Cancel` to `Cancel` diff --git a/.changeset/fuzzy-lamps-live.md b/.changeset/fuzzy-lamps-live.md new file mode 100644 index 0000000000..0611ccb98f --- /dev/null +++ b/.changeset/fuzzy-lamps-live.md @@ -0,0 +1,5 @@ +--- +"effect": minor +--- + +change `Runtime.RunCallbackOptions` type parameters order from `RunCallbackOptions` to `RunCallbackOptions` diff --git a/packages/effect/src/Effect.ts b/packages/effect/src/Effect.ts index 4d4a706ca8..de96cd21e0 100644 --- a/packages/effect/src/Effect.ts +++ b/packages/effect/src/Effect.ts @@ -4714,8 +4714,8 @@ export const runFork: ( */ export const runCallback: ( effect: Effect, - options?: Runtime.RunCallbackOptions | undefined -) => Runtime.Cancel = _runtime.unsafeRunEffect + options?: Runtime.RunCallbackOptions | undefined +) => Runtime.Cancel = _runtime.unsafeRunEffect /** * Runs an `Effect` workflow, returning a `Promise` which resolves with the diff --git a/packages/effect/src/Runtime.ts b/packages/effect/src/Runtime.ts index 1b66fc3acd..f6e6745c5c 100644 --- a/packages/effect/src/Runtime.ts +++ b/packages/effect/src/Runtime.ts @@ -19,7 +19,7 @@ import type { Scope } from "./Scope.js" * @since 2.0.0 * @category models */ -export interface AsyncFiberException { +export interface AsyncFiberException { readonly _tag: "AsyncFiberException" readonly fiber: Fiber.RuntimeFiber } @@ -28,8 +28,8 @@ export interface AsyncFiberException { * @since 2.0.0 * @category models */ -export interface Cancel { - (fiberId?: FiberId.FiberId, options?: RunCallbackOptions | undefined): void +export interface Cancel { + (fiberId?: FiberId.FiberId, options?: RunCallbackOptions | undefined): void } /** @@ -100,7 +100,7 @@ export const runSync: (runtime: Runtime) => (effect: Effect.Effect extends RunForkOptions { +export interface RunCallbackOptions extends RunForkOptions { readonly onExit?: ((exit: Exit.Exit) => void) | undefined } @@ -116,10 +116,10 @@ export interface RunCallbackOptions extends RunForkOptions { */ export const runCallback: ( runtime: Runtime -) => ( +) => ( effect: Effect.Effect, - options?: RunCallbackOptions | undefined -) => (fiberId?: FiberId.FiberId | undefined, options?: RunCallbackOptions | undefined) => void = + options?: RunCallbackOptions | undefined +) => (fiberId?: FiberId.FiberId | undefined, options?: RunCallbackOptions | undefined) => void = internal.unsafeRunCallback /** diff --git a/packages/effect/src/Stream.ts b/packages/effect/src/Stream.ts index d4a76893f7..0007eebc4e 100644 --- a/packages/effect/src/Stream.ts +++ b/packages/effect/src/Stream.ts @@ -3873,7 +3873,7 @@ export const toQueueOfElements: { * @since 2.0.0 * @category destructors */ -export const toReadableStream: (source: Stream) => ReadableStream = internal.toReadableStream +export const toReadableStream: (source: Stream) => ReadableStream = internal.toReadableStream /** * Applies the transducer to the stream and emits its outputs. diff --git a/packages/effect/src/internal/keyedPool.ts b/packages/effect/src/internal/keyedPool.ts index 9dd786f152..420d94915e 100644 --- a/packages/effect/src/internal/keyedPool.ts +++ b/packages/effect/src/internal/keyedPool.ts @@ -53,7 +53,7 @@ class KeyedPoolImpl implements KeyedPool.KeyedPoo } } -type MapValue = Complete | Pending +type MapValue = Complete | Pending class Complete implements Equal.Equal { readonly _tag = "Complete" @@ -101,22 +101,22 @@ const makeImpl = ( fiberRuntime.all([ core.context(), core.fiberId, - core.sync(() => MutableRef.make(HashMap.empty>())), + core.sync(() => MutableRef.make(HashMap.empty>())), fiberRuntime.scopeMake() ]), core.map(([context, fiberId, map, scope]) => { const getOrCreatePool = (key: K): Effect.Effect> => core.suspend(() => { - let value: MapValue | undefined = Option.getOrUndefined(HashMap.get(MutableRef.get(map), key)) + let value: MapValue | undefined = Option.getOrUndefined(HashMap.get(MutableRef.get(map), key)) if (value === undefined) { return core.uninterruptibleMask((restore) => { const deferred = core.deferredUnsafeMake>(fiberId) value = new Pending(deferred) - let previous: MapValue | undefined = undefined + let previous: MapValue | undefined = undefined if (HashMap.has(MutableRef.get(map), key)) { previous = Option.getOrUndefined(HashMap.get(MutableRef.get(map), key)) } else { - MutableRef.update(map, HashMap.set(key, value as MapValue)) + MutableRef.update(map, HashMap.set(key, value as MapValue)) } if (previous === undefined) { return pipe( @@ -143,7 +143,7 @@ const makeImpl = ( ) }, onSuccess: (pool) => { - MutableRef.update(map, HashMap.set(key, new Complete(pool) as MapValue)) + MutableRef.update(map, HashMap.set(key, new Complete(pool) as MapValue)) return core.as( core.deferredSucceed(deferred, pool), pool diff --git a/packages/effect/src/internal/pool.ts b/packages/effect/src/internal/pool.ts index 67e32b28b4..dd2e0e9a58 100644 --- a/packages/effect/src/internal/pool.ts +++ b/packages/effect/src/internal/pool.ts @@ -39,7 +39,7 @@ interface PoolState { readonly free: number } -interface Attempted { +interface Attempted { readonly result: Exit.Exit readonly finalizer: Effect.Effect } @@ -141,7 +141,7 @@ class PoolImpl implements Pool.Pool { readonly max: number, readonly isShuttingDown: Ref.Ref, readonly state: Ref.Ref, - readonly items: Queue.Queue>, + readonly items: Queue.Queue>, readonly invalidated: Ref.Ref>, readonly track: (exit: Exit.Exit) => Effect.Effect ) {} @@ -178,7 +178,7 @@ class PoolImpl implements Pool.Pool { get get(): Effect.Effect { const acquire = ( restore: (effect: Effect.Effect) => Effect.Effect - ): Effect.Effect> => + ): Effect.Effect> => core.flatMap(ref.get(this.isShuttingDown), (down) => down ? core.interrupt @@ -214,7 +214,7 @@ class PoolImpl implements Pool.Pool { return [core.interrupt, state] as const }))) - const release = (attempted: Attempted): Effect.Effect => + const release = (attempted: Attempted): Effect.Effect => core.exitMatch(attempted.result, { onFailure: () => core.flatten(ref.modify(this.state, (state) => { @@ -266,7 +266,7 @@ const allocate = ( core.exit(restore(fiberRuntime.scopeExtend(self.creator, scope))), (exit) => core.flatMap( - core.succeed>({ + core.succeed>({ result: exit as Exit.Exit, finalizer: core.scopeClose(scope, core.exitSucceed(void 0)) }), @@ -292,7 +292,7 @@ const excess = (self: PoolImpl): Effect.Effect => const finalizeInvalid = ( self: PoolImpl, - attempted: Attempted + attempted: Attempted ): Effect.Effect => pipe( forEach(attempted, (a) => ref.update(self.invalidated, HashSet.remove(a))), @@ -337,7 +337,7 @@ const getAndShutdown = (self: PoolImpl): Effect.Effect => /** * Begins pre-allocating pool entries based on minimum pool size. */ -const initialize = (self: PoolImpl): Effect.Effect => +const initialize = (self: PoolImpl): Effect.Effect => fiberRuntime.replicateEffect( core.uninterruptibleMask((restore) => core.flatten(ref.modify(self.state, (state) => { @@ -357,7 +357,7 @@ const initialize = (self: PoolImpl): Effect.Effect => /** * Shrinks the pool down, but never to less than the minimum size. */ -const shrink = (self: PoolImpl): Effect.Effect => +const shrink = (self: PoolImpl): Effect.Effect => core.uninterruptible( core.flatten(ref.modify(self.state, (state) => { if (state.size > self.min && state.free > 0) { @@ -379,16 +379,16 @@ const shrink = (self: PoolImpl): Effect.Effect => })) ) -const shutdown = (self: PoolImpl): Effect.Effect => +const shutdown = (self: PoolImpl): Effect.Effect => core.flatten(ref.modify(self.isShuttingDown, (down) => down ? [queue.awaitShutdown(self.items), true] as const : [core.zipRight(getAndShutdown(self), queue.awaitShutdown(self.items)), true])) -const isFailure = (self: Attempted): boolean => core.exitIsFailure(self.result) +const isFailure = (self: Attempted): boolean => core.exitIsFailure(self.result) const forEach = ( - self: Attempted, + self: Attempted, f: (a: A) => Effect.Effect ): Effect.Effect => core.exitMatch(self.result, { @@ -396,7 +396,7 @@ const forEach = ( onSuccess: f }) -const toEffect = (self: Attempted): Effect.Effect => self.result +const toEffect = (self: Attempted): Effect.Effect => self.result /** * A more powerful variant of `make` that allows specifying a `Strategy` that @@ -417,7 +417,7 @@ const makeWith = ( core.context(), ref.make(false), ref.make({ size: 0, free: 0 }), - queue.bounded>(options.max), + queue.bounded>(options.max), ref.make(HashSet.empty()), options.strategy.initial() ]), diff --git a/packages/effect/src/internal/runtime.ts b/packages/effect/src/internal/runtime.ts index 173bf63b92..5f11c1228b 100644 --- a/packages/effect/src/internal/runtime.ts +++ b/packages/effect/src/internal/runtime.ts @@ -97,10 +97,10 @@ export const unsafeFork = (runtime: Runtime.Runtime) => /** @internal */ export const unsafeRunCallback = (runtime: Runtime.Runtime) => -( +( effect: Effect.Effect, - options: Runtime.RunCallbackOptions = {} -): (fiberId?: FiberId.FiberId, options?: Runtime.RunCallbackOptions | undefined) => void => { + options: Runtime.RunCallbackOptions = {} +): (fiberId?: FiberId.FiberId, options?: Runtime.RunCallbackOptions | undefined) => void => { const fiberRuntime = unsafeFork(runtime)(effect, options) if (options.onExit) { @@ -131,7 +131,7 @@ export const unsafeRunSync = (runtime: Runtime.Runtime) => (effect: } } -const asyncFiberException = (fiber: Fiber.RuntimeFiber): Runtime.AsyncFiberException => { +const asyncFiberException = (fiber: Fiber.RuntimeFiber): Runtime.AsyncFiberException => { const limit = Error.stackTraceLimit Error.stackTraceLimit = 0 const error = (new Error()) as any diff --git a/packages/effect/src/internal/sink.ts b/packages/effect/src/internal/sink.ts index 4abb7067a0..d10556854a 100644 --- a/packages/effect/src/internal/sink.ts +++ b/packages/effect/src/internal/sink.ts @@ -1825,7 +1825,7 @@ export const splitWhere = dual< core.fromEffect(Ref.make(Chunk.empty())), core.flatMap((ref) => pipe( - splitWhereSplitter(false, ref, f), + splitWhereSplitter(false, ref, f), channel.pipeToOrFail(toChannel(self)), core.collectElements, core.flatMap(([leftovers, z]) => @@ -1846,7 +1846,7 @@ export const splitWhere = dual< }) /** @internal */ -const splitWhereSplitter = ( +const splitWhereSplitter = ( written: boolean, leftovers: Ref.Ref>, f: Predicate @@ -1854,14 +1854,14 @@ const splitWhereSplitter = ( core.readWithCause({ onInput: (input) => { if (Chunk.isEmpty(input)) { - return splitWhereSplitter(written, leftovers, f) + return splitWhereSplitter(written, leftovers, f) } if (written) { const index = indexWhere(input, f) if (index === -1) { return channel.zipRight( core.write(input), - splitWhereSplitter(true, leftovers, f) + splitWhereSplitter(true, leftovers, f) ) } const [left, right] = Chunk.splitAt(input, index) @@ -1874,7 +1874,7 @@ const splitWhereSplitter = ( if (index === -1) { return channel.zipRight( core.write(input), - splitWhereSplitter(true, leftovers, f) + splitWhereSplitter(true, leftovers, f) ) } const [left, right] = pipe(input, Chunk.splitAt(Math.max(index, 1))) diff --git a/packages/effect/src/internal/stm/core.ts b/packages/effect/src/internal/stm/core.ts index 5427fdc022..474e98a0c8 100644 --- a/packages/effect/src/internal/stm/core.ts +++ b/packages/effect/src/internal/stm/core.ts @@ -204,7 +204,7 @@ export const unsafeAtomically = ( } case TryCommitOpCodes.OP_SUSPEND: { const txnId = TxnId.make() - const state: { value: STMState.STMState } = { value: STMState.running } + const state: { value: STMState.STMState } = { value: STMState.running } const effect = Effect.async( (k: (effect: Effect.Effect) => unknown): void => tryCommitAsync(fiberId, self, txnId, state, env, scheduler, priority, k) @@ -235,11 +235,11 @@ export const unsafeAtomically = ( const tryCommit = ( fiberId: FiberId.FiberId, stm: STM.STM, - state: { value: STMState.STMState }, + state: { value: STMState.STMState }, env: Context.Context, scheduler: Scheduler.Scheduler, priority: number -): TryCommit.TryCommit => { +): TryCommit.TryCommit => { const journal: Journal.Journal = new Map() const tExit = new STMDriver(stm, journal, fiberId, env).run() const analysis = Journal.analyzeJournal(journal) @@ -300,7 +300,7 @@ const tryCommitSync = ( env: Context.Context, scheduler: Scheduler.Scheduler, priority: number -): TryCommit.TryCommit => { +): TryCommit.TryCommit => { const journal: Journal.Journal = new Map() const tExit = new STMDriver(stm, journal, fiberId, env).run() const analysis = Journal.analyzeJournal(journal) @@ -355,7 +355,7 @@ const tryCommitAsync = ( fiberId: FiberId.FiberId, self: STM.STM, txnId: TxnId.TxnId, - state: { value: STMState.STMState }, + state: { value: STMState.STMState }, context: Context.Context, scheduler: Scheduler.Scheduler, priority: number, @@ -386,7 +386,7 @@ const completeTodos = ( journal: Journal.Journal, scheduler: Scheduler.Scheduler, priority: number -): TryCommit.TryCommit => { +): TryCommit.TryCommit => { const todos = Journal.collectTodos(journal) if (todos.size > 0) { scheduler.scheduleTask(() => Journal.execTodos(todos), priority) diff --git a/packages/effect/src/internal/stm/stm.ts b/packages/effect/src/internal/stm/stm.ts index c9b7e5fa5d..661f5604c3 100644 --- a/packages/effect/src/internal/stm/stm.ts +++ b/packages/effect/src/internal/stm/stm.ts @@ -38,7 +38,7 @@ export const acquireUseRelease = dual< release: (resource: A) => STM.STM ): Effect.Effect => Effect.uninterruptibleMask((restore) => { - let state: STMState.STMState = STMState.running + let state: STMState.STMState = STMState.running return pipe( restore( core.unsafeAtomically( diff --git a/packages/effect/src/internal/stm/stm/stmState.ts b/packages/effect/src/internal/stm/stm/stmState.ts index 288eb8cd6e..9c19706bfc 100644 --- a/packages/effect/src/internal/stm/stm/stmState.ts +++ b/packages/effect/src/internal/stm/stm/stmState.ts @@ -17,10 +17,10 @@ export const STMStateTypeId = Symbol.for(STMStateSymbolKey) export type STMStateTypeId = typeof STMStateTypeId /** @internal */ -export type STMState = Done | Interrupted | Running +export type STMState = Done | Interrupted | Running /** @internal */ -export interface Done extends Equal.Equal { +export interface Done extends Equal.Equal { readonly [STMStateTypeId]: STMStateTypeId readonly _tag: OpCodes.OP_DONE readonly exit: Exit.Exit @@ -42,22 +42,22 @@ export interface Running extends Equal.Equal { export const isSTMState = (u: unknown): u is STMState => hasProperty(u, STMStateTypeId) /** @internal */ -export const isRunning = (self: STMState): self is Running => { +export const isRunning = (self: STMState): self is Running => { return self._tag === OpCodes.OP_RUNNING } /** @internal */ -export const isDone = (self: STMState): self is Done => { +export const isDone = (self: STMState): self is Done => { return self._tag === OpCodes.OP_DONE } /** @internal */ -export const isInterrupted = (self: STMState): self is Interrupted => { +export const isInterrupted = (self: STMState): self is Interrupted => { return self._tag === OpCodes.OP_INTERRUPTED } /** @internal */ -export const done = (exit: Exit.Exit): STMState => { +export const done = (exit: Exit.Exit): STMState => { return { [STMStateTypeId]: STMStateTypeId, _tag: OpCodes.OP_DONE, @@ -108,7 +108,7 @@ export const running: STMState = { } /** @internal */ -export const fromTExit = (tExit: TExit.TExit): STMState => { +export const fromTExit = (tExit: TExit.TExit): STMState => { switch (tExit._tag) { case TExitOpCodes.OP_FAIL: { return done(Exit.fail(tExit.error)) diff --git a/packages/effect/src/internal/stm/stm/tryCommit.ts b/packages/effect/src/internal/stm/stm/tryCommit.ts index 54e58ac808..9ad518ef48 100644 --- a/packages/effect/src/internal/stm/stm/tryCommit.ts +++ b/packages/effect/src/internal/stm/stm/tryCommit.ts @@ -3,10 +3,10 @@ import * as OpCodes from "../opCodes/tryCommit.js" import type * as Journal from "./journal.js" /** @internal */ -export type TryCommit = Done | Suspend +export type TryCommit = Done | Suspend /** @internal */ -export interface Done { +export interface Done { readonly _tag: OpCodes.OP_DONE readonly exit: Exit.Exit } @@ -18,7 +18,7 @@ export interface Suspend { } /** @internal */ -export const done = (exit: Exit.Exit): TryCommit => { +export const done = (exit: Exit.Exit): TryCommit => { return { _tag: OpCodes.OP_DONE, exit diff --git a/packages/effect/src/internal/stream.ts b/packages/effect/src/internal/stream.ts index 34144e2900..d2aa89c50e 100644 --- a/packages/effect/src/internal/stream.ts +++ b/packages/effect/src/internal/stream.ts @@ -1680,7 +1680,7 @@ export const debounce = dual< ) }) const consumer = ( - state: DebounceState.DebounceState + state: DebounceState.DebounceState ): Channel.Channel, unknown, E, unknown, unknown, unknown> => { switch (state._tag) { case DebounceState.OP_NOT_STARTED: { @@ -4725,13 +4725,13 @@ export const rechunk = dual< >(2, (self: Stream.Stream, n: number): Stream.Stream => suspend(() => { const target = Math.max(n, 1) - const process = rechunkProcess(new StreamRechunker(target), target) + const process = rechunkProcess(new StreamRechunker(target), target) return new StreamImpl(pipe(toChannel(self), core.pipeTo(process))) })) /** @internal */ -const rechunkProcess = ( - rechunker: StreamRechunker, +const rechunkProcess = ( + rechunker: StreamRechunker, target: number ): Channel.Channel, Chunk.Chunk, E, E, unknown, unknown> => core.readWithCause({ @@ -4767,8 +4767,7 @@ const rechunkProcess = ( onDone: () => rechunker.emitIfNotEmpty() }) -/** @internal */ -class StreamRechunker { +class StreamRechunker { private builder: Array = [] private pos = 0 @@ -6656,7 +6655,7 @@ export const toQueueOfElements = dual< )) /** @internal */ -export const toReadableStream = (source: Stream.Stream) => { +export const toReadableStream = (source: Stream.Stream) => { let pull: Effect.Effect let scope: Scope.CloseableScope return new ReadableStream({ diff --git a/packages/effect/src/internal/stream/debounceState.ts b/packages/effect/src/internal/stream/debounceState.ts index f73deb3a15..957e77f9f8 100644 --- a/packages/effect/src/internal/stream/debounceState.ts +++ b/packages/effect/src/internal/stream/debounceState.ts @@ -3,7 +3,7 @@ import type * as Fiber from "../../Fiber.js" import type * as HandoffSignal from "./handoffSignal.js" /** @internal */ -export type DebounceState = NotStarted | Previous | Current +export type DebounceState = NotStarted | Previous | Current /** @internal */ export const OP_NOT_STARTED = "NotStarted" as const @@ -34,7 +34,7 @@ export interface Previous { } /** @internal */ -export interface Current { +export interface Current { readonly _tag: OP_CURRENT readonly fiber: Fiber.Fiber, E> } @@ -45,13 +45,13 @@ export const notStarted: DebounceState = { } /** @internal */ -export const previous = (fiber: Fiber.Fiber>): DebounceState => ({ +export const previous = (fiber: Fiber.Fiber>): DebounceState => ({ _tag: OP_PREVIOUS, fiber }) /** @internal */ -export const current = (fiber: Fiber.Fiber, E>): DebounceState => ({ +export const current = (fiber: Fiber.Fiber, E>): DebounceState => ({ _tag: OP_CURRENT, fiber })