@effect/io
Advanced tools
Comparing version 0.39.1 to 0.40.0
@@ -13,2 +13,3 @@ /** | ||
import type * as FiberId from "@effect/io/FiberId"; | ||
import type { FiberRef } from "@effect/io/FiberRef"; | ||
import type * as FiberRefs from "@effect/io/FiberRefs"; | ||
@@ -90,2 +91,10 @@ import type * as FiberStatus from "@effect/io/FiberStatus"; | ||
/** | ||
* Reads the current number of ops that have occurred since the last yield | ||
*/ | ||
get currentOpCount(): number; | ||
/** | ||
* Reads the current value of a fiber ref | ||
*/ | ||
getFiberRef<X>(fiberRef: FiberRef<X>): X; | ||
/** | ||
* The identity of the fiber. | ||
@@ -104,21 +113,13 @@ */ | ||
* Adds an observer to the list of observers. | ||
* | ||
* **NOTE**: This method must be invoked by the fiber itself. | ||
*/ | ||
unsafeAddObserver(observer: (exit: Exit.Exit<E, A>) => void): void; | ||
addObserver(observer: (exit: Exit.Exit<E, A>) => void): void; | ||
/** | ||
* Removes the specified observer from the list of observers that will be | ||
* notified when the fiber exits. | ||
* | ||
* **NOTE**: This method must be invoked by the fiber itself. | ||
*/ | ||
unsafeRemoveObserver(observer: (exit: Exit.Exit<E, A>) => void): void; | ||
removeObserver(observer: (exit: Exit.Exit<E, A>) => void): void; | ||
/** | ||
* Retrieves all fiber refs of the fiber. | ||
* | ||
* **NOTE**: This method is safe to invoke on any fiber, but if not invoked | ||
* on this fiber, then values derived from the fiber's state (including the | ||
* log annotations and log level) may not be up-to-date. | ||
*/ | ||
unsafeGetFiberRefs(): FiberRefs.FiberRefs; | ||
getFiberRefs(): FiberRefs.FiberRefs; | ||
/** | ||
@@ -125,0 +126,0 @@ * Unsafely observes the fiber, but returns immediately if it is not |
@@ -21,3 +21,3 @@ /** | ||
import type * as RuntimeFlags from "@effect/io/RuntimeFlags"; | ||
import type * as Scheduler from "@effect/io/Scheduler"; | ||
import * as Scheduler from "@effect/io/Scheduler"; | ||
import type * as Scope from "@effect/io/Scope"; | ||
@@ -237,3 +237,3 @@ import type * as Supervisor from "@effect/io/Supervisor"; | ||
*/ | ||
export declare const currentMaxFiberOps: FiberRef<number>; | ||
export declare const currentMaxOpsBeforeYield: FiberRef<number>; | ||
/** | ||
@@ -240,0 +240,0 @@ * @since 1.0.0 |
@@ -6,6 +6,7 @@ "use strict"; | ||
}); | ||
exports.updateSomeAndGet = exports.updateSome = exports.updateAndGet = exports.update = exports.unsafeMakeSupervisor = exports.unsafeMakePatch = exports.unsafeMakeHashSet = exports.unsafeMakeContext = exports.unsafeMake = exports.unhandledErrorLogLevel = exports.set = exports.reset = exports.modifySome = exports.modify = exports.makeWith = exports.makeRuntimeFlags = exports.makeContext = exports.make = exports.interruptedCause = exports.getWith = exports.getAndUpdateSome = exports.getAndUpdate = exports.getAndSet = exports.get = exports.delete = exports.currentTracerTimingEnabled = exports.currentTracerSpanLinks = exports.currentTracerSpanAnnotations = exports.currentTracerSpan = exports.currentSupervisor = exports.currentSchedulingPriority = exports.currentScheduler = exports.currentRuntimeFlags = exports.currentRequestCacheEnabled = exports.currentRequestCache = exports.currentRequestBatchingEnabled = exports.currentMinimumLogLevel = exports.currentMetricLabels = exports.currentMaxFiberOps = exports.currentLoggers = exports.currentLogSpan = exports.currentLogLevel = exports.currentLogAnnotations = exports.currentContext = exports.FiberRefTypeId = void 0; | ||
exports.updateSomeAndGet = exports.updateSome = exports.updateAndGet = exports.update = exports.unsafeMakeSupervisor = exports.unsafeMakePatch = exports.unsafeMakeHashSet = exports.unsafeMakeContext = exports.unsafeMake = exports.unhandledErrorLogLevel = exports.set = exports.reset = exports.modifySome = exports.modify = exports.makeWith = exports.makeRuntimeFlags = exports.makeContext = exports.make = exports.interruptedCause = exports.getWith = exports.getAndUpdateSome = exports.getAndUpdate = exports.getAndSet = exports.get = exports.delete = exports.currentTracerTimingEnabled = exports.currentTracerSpanLinks = exports.currentTracerSpanAnnotations = exports.currentTracerSpan = exports.currentSupervisor = exports.currentSchedulingPriority = exports.currentScheduler = exports.currentRuntimeFlags = exports.currentRequestCacheEnabled = exports.currentRequestCache = exports.currentRequestBatchingEnabled = exports.currentMinimumLogLevel = exports.currentMetricLabels = exports.currentMaxOpsBeforeYield = exports.currentLoggers = exports.currentLogSpan = exports.currentLogLevel = exports.currentLogAnnotations = exports.currentContext = exports.FiberRefTypeId = void 0; | ||
var core = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/io/internal/core")); | ||
var fiberRuntime = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/io/internal/fiberRuntime")); | ||
var query = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/io/internal/query")); | ||
var Scheduler = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/io/Scheduler")); | ||
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); } | ||
@@ -187,3 +188,3 @@ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; } | ||
exports.currentSchedulingPriority = currentSchedulingPriority; | ||
const currentMaxFiberOps = core.currentMaxFiberOps; | ||
const currentMaxOpsBeforeYield = core.currentMaxOpsBeforeYield; | ||
/** | ||
@@ -193,3 +194,3 @@ * @since 1.0.0 | ||
*/ | ||
exports.currentMaxFiberOps = currentMaxFiberOps; | ||
exports.currentMaxOpsBeforeYield = currentMaxOpsBeforeYield; | ||
const unhandledErrorLogLevel = core.currentUnhandledErrorLogLevel; | ||
@@ -237,3 +238,3 @@ /** | ||
exports.currentRuntimeFlags = currentRuntimeFlags; | ||
const currentScheduler = core.currentScheduler; | ||
const currentScheduler = Scheduler.currentScheduler; | ||
/** | ||
@@ -240,0 +241,0 @@ * @since 1.0.0 |
@@ -349,3 +349,3 @@ "use strict"; | ||
exports.gen = gen; | ||
const fiberRefs = /*#__PURE__*/core.withFiberRuntime(state => core.succeed(state.unsafeGetFiberRefs())); | ||
const fiberRefs = /*#__PURE__*/core.withFiberRuntime(state => core.succeed(state.getFiberRefs())); | ||
/* @internal */ | ||
@@ -755,3 +755,3 @@ exports.fiberRefs = fiberRefs; | ||
const updateFiberRefs = f => core.withFiberRuntime(state => { | ||
state.setFiberRefs(f(state.id(), state.unsafeGetFiberRefs())); | ||
state.setFiberRefs(f(state.id(), state.getFiberRefs())); | ||
return core.unit; | ||
@@ -758,0 +758,0 @@ }); |
@@ -28,2 +28,3 @@ "use strict"; | ||
var supervisor = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/io/internal/supervisor")); | ||
var _Scheduler = /*#__PURE__*/require("@effect/io/Scheduler"); | ||
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); } | ||
@@ -63,3 +64,3 @@ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; } | ||
this.taken -= n; | ||
fiber.getFiberRef(core.currentScheduler).scheduleTask(() => { | ||
fiber.getFiberRef(_Scheduler.currentScheduler).scheduleTask(() => { | ||
this.waiters.forEach(wake => wake()); | ||
@@ -66,0 +67,0 @@ }, fiber.getFiberRef(core.currentSchedulingPriority)); |
@@ -27,3 +27,3 @@ "use strict"; | ||
this.roots.add(child); | ||
child.unsafeAddObserver(() => { | ||
child.addObserver(() => { | ||
this.roots.delete(child); | ||
@@ -44,3 +44,3 @@ }); | ||
parentFiber.addChild(child); | ||
child.unsafeAddObserver(() => { | ||
child.addObserver(() => { | ||
parentFiber.removeChild(child); | ||
@@ -47,0 +47,0 @@ }); |
@@ -37,3 +37,3 @@ "use strict"; | ||
fiberId, | ||
fiberRef: core.currentScheduler, | ||
fiberRef: _scheduler.currentScheduler, | ||
value: options.scheduler | ||
@@ -49,3 +49,3 @@ }); | ||
supervisor.onStart(runtime.context, effect, Option.none(), fiberRuntime); | ||
fiberRuntime.unsafeAddObserver(exit => supervisor.onEnd(exit, fiberRuntime)); | ||
fiberRuntime.addObserver(exit => supervisor.onEnd(exit, fiberRuntime)); | ||
} | ||
@@ -61,3 +61,3 @@ fiberScope.globalScope.add(runtime.runtimeFlags, fiberRuntime); | ||
if (onExit) { | ||
fiberRuntime.unsafeAddObserver(exit => { | ||
fiberRuntime.addObserver(exit => { | ||
onExit(exit); | ||
@@ -214,3 +214,3 @@ }); | ||
} | ||
unsafeFork(runtime)(effect).unsafeAddObserver(exit => { | ||
unsafeFork(runtime)(effect).addObserver(exit => { | ||
resolve(exit); | ||
@@ -233,6 +233,6 @@ }); | ||
exports.RuntimeImpl = RuntimeImpl; | ||
const make = options => new RuntimeImpl(options.context, options.flags, options.fiberRefs); | ||
const make = options => new RuntimeImpl(options.context, options.runtimeFlags, options.fiberRefs); | ||
/** @internal */ | ||
exports.make = make; | ||
const runtime = () => core.withFiberRuntime((state, status) => core.succeed(new RuntimeImpl(state.getFiberRef(core.currentContext), status.runtimeFlags, state.unsafeGetFiberRefs()))); | ||
const runtime = () => core.withFiberRuntime((state, status) => core.succeed(new RuntimeImpl(state.getFiberRef(core.currentContext), status.runtimeFlags, state.getFiberRefs()))); | ||
/** @internal */ | ||
@@ -245,3 +245,3 @@ exports.runtime = runtime; | ||
context: /*#__PURE__*/Context.empty(), | ||
flags: defaultRuntimeFlags, | ||
runtimeFlags: defaultRuntimeFlags, | ||
fiberRefs: /*#__PURE__*/FiberRefs.unsafeMake( /*#__PURE__*/new Map()) | ||
@@ -248,0 +248,0 @@ }); |
@@ -91,3 +91,3 @@ /** | ||
*/ | ||
export declare const addScoped: <R, E, A>(effect: Effect<R | Scope, E, Logger<unknown, A>>) => Layer.Layer<Exclude<R, Scope>, E, never>; | ||
export declare const addScoped: <R, E, A>(effect: Effect<R, E, Logger<unknown, A>>) => Layer.Layer<Exclude<R, Scope>, E, never>; | ||
/** | ||
@@ -153,4 +153,4 @@ * @since 1.0.0 | ||
export declare const replaceScoped: { | ||
<R, E, B>(that: Effect<Scope | R, E, Logger<unknown, B>>): <A>(self: Logger<unknown, A>) => Layer.Layer<Exclude<R, Scope>, E, never>; | ||
<A, R, E, B>(self: Logger<unknown, A>, that: Effect<Scope | R, E, Logger<unknown, B>>): Layer.Layer<Exclude<R, Scope>, E, never>; | ||
<R, E, B>(that: Effect<R, E, Logger<unknown, B>>): <A>(self: Logger<unknown, A>) => Layer.Layer<Exclude<R, Scope>, E, never>; | ||
<A, R, E, B>(self: Logger<unknown, A>, that: Effect<R, E, Logger<unknown, B>>): Layer.Layer<Exclude<R, Scope>, E, never>; | ||
}; | ||
@@ -157,0 +157,0 @@ /** |
{ | ||
"name": "@effect/io", | ||
"version": "0.39.1", | ||
"version": "0.40.0", | ||
"description": "Functional programming in TypeScript", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
@@ -133,3 +133,3 @@ /** | ||
readonly context: Context.Context<R>; | ||
readonly flags: RuntimeFlags.RuntimeFlags; | ||
readonly runtimeFlags: RuntimeFlags.RuntimeFlags; | ||
readonly fiberRefs: FiberRefs.FiberRefs; | ||
@@ -136,0 +136,0 @@ }) => Runtime<R>; |
/** | ||
* @since 1.0.0 | ||
*/ | ||
import type { RuntimeFiber } from "@effect/io/Fiber"; | ||
/** | ||
@@ -14,2 +15,3 @@ * @since 1.0.0 | ||
export interface Scheduler { | ||
shouldYield(fiber: RuntimeFiber<unknown, unknown>): number | false; | ||
scheduleTask(task: Task, priority: number): void; | ||
@@ -64,2 +66,6 @@ } | ||
*/ | ||
shouldYield(fiber: RuntimeFiber<unknown, unknown>): number | false; | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
scheduleTask(task: Task, priority: number): void; | ||
@@ -92,2 +98,6 @@ } | ||
*/ | ||
shouldYield(fiber: RuntimeFiber<unknown, unknown>): number | false; | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
flush(): void; | ||
@@ -115,2 +125,6 @@ } | ||
*/ | ||
shouldYield(fiber: RuntimeFiber<unknown, unknown>): number | false; | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
step(): void; | ||
@@ -125,5 +139,10 @@ } | ||
* @since 1.0.0 | ||
* @category utilities | ||
*/ | ||
export declare const defaultShouldYield: Scheduler["shouldYield"]; | ||
/** | ||
* @since 1.0.0 | ||
* @category constructors | ||
*/ | ||
export declare const make: (scheduleTask: Scheduler["scheduleTask"]) => Scheduler; | ||
export declare const make: (scheduleTask: Scheduler["scheduleTask"], shouldYield?: Scheduler["shouldYield"]) => Scheduler; | ||
/** | ||
@@ -133,3 +152,3 @@ * @since 1.0.0 | ||
*/ | ||
export declare const makeBatched: (callback: (runBatch: () => void) => void) => Scheduler; | ||
export declare const makeBatched: (callback: (runBatch: () => void) => void, shouldYield?: Scheduler["shouldYield"]) => Scheduler; | ||
/** | ||
@@ -139,3 +158,3 @@ * @since 1.0.0 | ||
*/ | ||
export declare const timer: (ms: number) => Scheduler; | ||
export declare const timer: (ms: number, shouldYield?: Scheduler["shouldYield"]) => Scheduler; | ||
/** | ||
@@ -145,3 +164,3 @@ * @since 1.0.0 | ||
*/ | ||
export declare const timerBatched: (ms: number) => Scheduler; | ||
export declare const timerBatched: (ms: number, shouldYield?: Scheduler["shouldYield"]) => Scheduler; | ||
//# sourceMappingURL=Scheduler.d.ts.map |
@@ -6,4 +6,8 @@ "use strict"; | ||
}); | ||
exports.timerBatched = exports.timer = exports.makeMatrix = exports.makeBatched = exports.make = exports.defaultScheduler = exports.SyncScheduler = exports.PriorityBuckets = exports.MixedScheduler = exports.ControlledScheduler = void 0; | ||
exports.withScheduler = exports.timerBatched = exports.timer = exports.makeMatrix = exports.makeBatched = exports.make = exports.defaultShouldYield = exports.defaultScheduler = exports.currentScheduler = exports.SyncScheduler = exports.PriorityBuckets = exports.MixedScheduler = exports.ControlledScheduler = void 0; | ||
var _Function = /*#__PURE__*/require("@effect/data/Function"); | ||
var _GlobalValue = /*#__PURE__*/require("@effect/data/GlobalValue"); | ||
var core = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/io/internal/core")); | ||
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); } | ||
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; } | ||
/** | ||
@@ -103,2 +107,8 @@ * @since 1.0.0 | ||
*/ | ||
shouldYield(fiber) { | ||
return fiber.currentOpCount > fiber.getFiberRef(core.currentMaxOpsBeforeYield) ? fiber.getFiberRef(core.currentSchedulingPriority) : false; | ||
} | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
scheduleTask(task, priority) { | ||
@@ -147,2 +157,8 @@ this.tasks.scheduleTask(task, priority); | ||
*/ | ||
shouldYield(fiber) { | ||
return fiber.currentOpCount > fiber.getFiberRef(core.currentMaxOpsBeforeYield) ? fiber.getFiberRef(core.currentSchedulingPriority) : false; | ||
} | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
flush() { | ||
@@ -190,2 +206,8 @@ while (this.tasks.buckets.length > 0) { | ||
*/ | ||
shouldYield(fiber) { | ||
return fiber.currentOpCount > fiber.getFiberRef(core.currentMaxOpsBeforeYield) ? fiber.getFiberRef(core.currentSchedulingPriority) : false; | ||
} | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
step() { | ||
@@ -209,2 +231,11 @@ const tasks = this.tasks.buckets; | ||
return { | ||
shouldYield(fiber) { | ||
for (const scheduler of record) { | ||
const priority = scheduler[1].shouldYield(fiber); | ||
if (priority !== false) { | ||
return priority; | ||
} | ||
} | ||
return false; | ||
}, | ||
scheduleTask(task, priority) { | ||
@@ -225,7 +256,16 @@ let scheduler = undefined; | ||
* @since 1.0.0 | ||
* @category utilities | ||
*/ | ||
exports.makeMatrix = makeMatrix; | ||
const defaultShouldYield = fiber => { | ||
return fiber.currentOpCount > fiber.getFiberRef(core.currentMaxOpsBeforeYield) ? fiber.getFiberRef(core.currentSchedulingPriority) : false; | ||
}; | ||
/** | ||
* @since 1.0.0 | ||
* @category constructors | ||
*/ | ||
exports.makeMatrix = makeMatrix; | ||
const make = scheduleTask => ({ | ||
scheduleTask | ||
exports.defaultShouldYield = defaultShouldYield; | ||
const make = (scheduleTask, shouldYield = defaultShouldYield) => ({ | ||
scheduleTask, | ||
shouldYield | ||
}); | ||
@@ -237,3 +277,3 @@ /** | ||
exports.make = make; | ||
const makeBatched = callback => { | ||
const makeBatched = (callback, shouldYield = defaultShouldYield) => { | ||
let running = false; | ||
@@ -262,3 +302,3 @@ const tasks = new PriorityBuckets(); | ||
} | ||
}); | ||
}, shouldYield); | ||
}; | ||
@@ -270,3 +310,3 @@ /** | ||
exports.makeBatched = makeBatched; | ||
const timer = ms => make(task => setTimeout(task, ms)); | ||
const timer = (ms, shouldYield = defaultShouldYield) => make(task => setTimeout(task, ms), shouldYield); | ||
/** | ||
@@ -277,4 +317,10 @@ * @since 1.0.0 | ||
exports.timer = timer; | ||
const timerBatched = ms => makeBatched(task => setTimeout(task, ms)); | ||
const timerBatched = (ms, shouldYield = defaultShouldYield) => makeBatched(task => setTimeout(task, ms), shouldYield); | ||
/** @internal */ | ||
exports.timerBatched = timerBatched; | ||
const currentScheduler = /*#__PURE__*/(0, _GlobalValue.globalValue)( /*#__PURE__*/Symbol.for("@effect/io/FiberRef/currentScheduler"), () => core.fiberRefUnsafeMake(defaultScheduler)); | ||
/** @internal */ | ||
exports.currentScheduler = currentScheduler; | ||
const withScheduler = /*#__PURE__*/(0, _Function.dual)(2, (self, scheduler) => core.fiberRefLocally(self, currentScheduler, scheduler)); | ||
exports.withScheduler = withScheduler; | ||
//# sourceMappingURL=Scheduler.js.map |
@@ -13,2 +13,3 @@ /** | ||
import type * as FiberId from "@effect/io/FiberId" | ||
import type { FiberRef } from "@effect/io/FiberRef" | ||
import type * as FiberRefs from "@effect/io/FiberRefs" | ||
@@ -105,2 +106,12 @@ import type * as FiberStatus from "@effect/io/FiberStatus" | ||
/** | ||
* Reads the current number of ops that have occurred since the last yield | ||
*/ | ||
get currentOpCount(): number | ||
/** | ||
* Reads the current value of a fiber ref | ||
*/ | ||
getFiberRef<X>(fiberRef: FiberRef<X>): X | ||
/** | ||
* The identity of the fiber. | ||
@@ -122,6 +133,4 @@ */ | ||
* Adds an observer to the list of observers. | ||
* | ||
* **NOTE**: This method must be invoked by the fiber itself. | ||
*/ | ||
unsafeAddObserver(observer: (exit: Exit.Exit<E, A>) => void): void | ||
addObserver(observer: (exit: Exit.Exit<E, A>) => void): void | ||
@@ -131,15 +140,9 @@ /** | ||
* notified when the fiber exits. | ||
* | ||
* **NOTE**: This method must be invoked by the fiber itself. | ||
*/ | ||
unsafeRemoveObserver(observer: (exit: Exit.Exit<E, A>) => void): void | ||
removeObserver(observer: (exit: Exit.Exit<E, A>) => void): void | ||
/** | ||
* Retrieves all fiber refs of the fiber. | ||
* | ||
* **NOTE**: This method is safe to invoke on any fiber, but if not invoked | ||
* on this fiber, then values derived from the fiber's state (including the | ||
* log annotations and log level) may not be up-to-date. | ||
*/ | ||
unsafeGetFiberRefs(): FiberRefs.FiberRefs | ||
getFiberRefs(): FiberRefs.FiberRefs | ||
@@ -146,0 +149,0 @@ /** |
@@ -24,3 +24,3 @@ /** | ||
import type * as RuntimeFlags from "@effect/io/RuntimeFlags" | ||
import type * as Scheduler from "@effect/io/Scheduler" | ||
import * as Scheduler from "@effect/io/Scheduler" | ||
import type * as Scope from "@effect/io/Scope" | ||
@@ -308,3 +308,3 @@ import type * as Supervisor from "@effect/io/Supervisor" | ||
*/ | ||
export const currentMaxFiberOps: FiberRef<number> = core.currentMaxFiberOps | ||
export const currentMaxOpsBeforeYield: FiberRef<number> = core.currentMaxOpsBeforeYield | ||
@@ -358,3 +358,3 @@ /** | ||
*/ | ||
export const currentScheduler: FiberRef<Scheduler.Scheduler> = core.currentScheduler | ||
export const currentScheduler: FiberRef<Scheduler.Scheduler> = Scheduler.currentScheduler | ||
@@ -361,0 +361,0 @@ /** |
@@ -31,2 +31,3 @@ import * as Duration from "@effect/data/Duration" | ||
import type * as Schedule from "@effect/io/Schedule" | ||
import { currentScheduler } from "@effect/io/Scheduler" | ||
import type * as Scope from "@effect/io/Scope" | ||
@@ -75,3 +76,3 @@ import type * as Supervisor from "@effect/io/Supervisor" | ||
this.taken -= n | ||
fiber.getFiberRef(core.currentScheduler).scheduleTask(() => { | ||
fiber.getFiberRef(currentScheduler).scheduleTask(() => { | ||
this.waiters.forEach((wake) => wake()) | ||
@@ -78,0 +79,0 @@ }, fiber.getFiberRef(core.currentSchedulingPriority)) |
@@ -37,3 +37,3 @@ import { globalValue } from "@effect/data/GlobalValue" | ||
this.roots.add(child) | ||
child.unsafeAddObserver(() => { | ||
child.addObserver(() => { | ||
this.roots.delete(child) | ||
@@ -56,3 +56,3 @@ }) | ||
parentFiber.addChild(child) | ||
child.unsafeAddObserver(() => { | ||
child.addObserver(() => { | ||
parentFiber.removeChild(child) | ||
@@ -59,0 +59,0 @@ }) |
@@ -59,3 +59,3 @@ import type * as Context from "@effect/data/Context" | ||
export const addLoggerScoped = <R, E, A>( | ||
effect: Effect.Effect<R | Scope, E, Logger.Logger<unknown, A>> | ||
effect: Effect.Effect<R, E, Logger.Logger<unknown, A>> | ||
): Layer.Layer<Exclude<R, Scope>, E, never> => | ||
@@ -95,7 +95,7 @@ Layer.unwrapScoped( | ||
<R, E, B>( | ||
that: Effect.Effect<R | Scope, E, Logger.Logger<unknown, B>> | ||
that: Effect.Effect<R, E, Logger.Logger<unknown, B>> | ||
) => <A>(self: Logger.Logger<unknown, A>) => Layer.Layer<Exclude<R, Scope>, E, never>, | ||
<A, R, E, B>( | ||
self: Logger.Logger<unknown, A>, | ||
that: Effect.Effect<R | Scope, E, Logger.Logger<unknown, B>> | ||
that: Effect.Effect<R, E, Logger.Logger<unknown, B>> | ||
) => Layer.Layer<Exclude<R, Scope>, E, never> | ||
@@ -102,0 +102,0 @@ >(2, (self, that) => layer.flatMap(removeLogger(self), () => addLoggerScoped(that))) |
@@ -43,3 +43,3 @@ import * as Context from "@effect/data/Context" | ||
fiberId, | ||
fiberRef: core.currentScheduler, | ||
fiberRef: _scheduler.currentScheduler, | ||
value: options.scheduler | ||
@@ -64,3 +64,3 @@ }) | ||
fiberRuntime.unsafeAddObserver((exit) => supervisor.onEnd(exit, fiberRuntime)) | ||
fiberRuntime.addObserver((exit) => supervisor.onEnd(exit, fiberRuntime)) | ||
} | ||
@@ -84,3 +84,3 @@ | ||
if (onExit) { | ||
fiberRuntime.unsafeAddObserver((exit) => { | ||
fiberRuntime.addObserver((exit) => { | ||
onExit(exit) | ||
@@ -249,3 +249,3 @@ }) | ||
} | ||
unsafeFork(runtime)(effect).unsafeAddObserver((exit) => { | ||
unsafeFork(runtime)(effect).addObserver((exit) => { | ||
resolve(exit) | ||
@@ -272,6 +272,6 @@ }) | ||
readonly context: Context.Context<R> | ||
readonly flags: RuntimeFlags.RuntimeFlags | ||
readonly runtimeFlags: RuntimeFlags.RuntimeFlags | ||
readonly fiberRefs: FiberRefs.FiberRefs | ||
} | ||
): Runtime.Runtime<R> => new RuntimeImpl(options.context, options.flags, options.fiberRefs) | ||
): Runtime.Runtime<R> => new RuntimeImpl(options.context, options.runtimeFlags, options.fiberRefs) | ||
@@ -285,3 +285,3 @@ /** @internal */ | ||
status.runtimeFlags, | ||
state.unsafeGetFiberRefs() | ||
state.getFiberRefs() | ||
) | ||
@@ -301,3 +301,3 @@ ) | ||
context: Context.empty(), | ||
flags: defaultRuntimeFlags, | ||
runtimeFlags: defaultRuntimeFlags, | ||
fiberRefs: FiberRefs.unsafeMake(new Map()) | ||
@@ -304,0 +304,0 @@ }) |
@@ -112,3 +112,3 @@ /** | ||
export const addScoped: <R, E, A>( | ||
effect: Effect<R | Scope, E, Logger<unknown, A>> | ||
effect: Effect<R, E, Logger<unknown, A>> | ||
) => Layer.Layer<Exclude<R, Scope>, E, never> = circular.addLoggerScoped | ||
@@ -199,7 +199,7 @@ | ||
<R, E, B>( | ||
that: Effect<Scope | R, E, Logger<unknown, B>> | ||
that: Effect<R, E, Logger<unknown, B>> | ||
): <A>(self: Logger<unknown, A>) => Layer.Layer<Exclude<R, Scope>, E, never> | ||
<A, R, E, B>( | ||
self: Logger<unknown, A>, | ||
that: Effect<Scope | R, E, Logger<unknown, B>> | ||
that: Effect<R, E, Logger<unknown, B>> | ||
): Layer.Layer<Exclude<R, Scope>, E, never> | ||
@@ -206,0 +206,0 @@ } = circular.replaceLoggerScoped |
@@ -161,3 +161,3 @@ /** | ||
readonly context: Context.Context<R> | ||
readonly flags: RuntimeFlags.RuntimeFlags | ||
readonly runtimeFlags: RuntimeFlags.RuntimeFlags | ||
readonly fiberRefs: FiberRefs.FiberRefs | ||
@@ -164,0 +164,0 @@ } |
@@ -5,3 +5,8 @@ /** | ||
import { dual } from "@effect/data/Function" | ||
import { globalValue } from "@effect/data/GlobalValue" | ||
import type { Effect } from "@effect/io/Effect" | ||
import type { RuntimeFiber } from "@effect/io/Fiber" | ||
import type { FiberRef } from "@effect/io/FiberRef" | ||
import * as core from "@effect/io/internal/core" | ||
@@ -19,2 +24,3 @@ /** | ||
export interface Scheduler { | ||
shouldYield(fiber: RuntimeFiber<unknown, unknown>): number | false | ||
scheduleTask(task: Task, priority: number): void | ||
@@ -114,2 +120,11 @@ } | ||
*/ | ||
shouldYield(fiber: RuntimeFiber<unknown, unknown>): number | false { | ||
return fiber.currentOpCount > fiber.getFiberRef(core.currentMaxOpsBeforeYield) | ||
? fiber.getFiberRef(core.currentSchedulingPriority) | ||
: false | ||
} | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
scheduleTask(task: Task, priority: number) { | ||
@@ -162,2 +177,11 @@ this.tasks.scheduleTask(task, priority) | ||
*/ | ||
shouldYield(fiber: RuntimeFiber<unknown, unknown>): number | false { | ||
return fiber.currentOpCount > fiber.getFiberRef(core.currentMaxOpsBeforeYield) | ||
? fiber.getFiberRef(core.currentSchedulingPriority) | ||
: false | ||
} | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
flush() { | ||
@@ -206,2 +230,11 @@ while (this.tasks.buckets.length > 0) { | ||
*/ | ||
shouldYield(fiber: RuntimeFiber<unknown, unknown>): number | false { | ||
return fiber.currentOpCount > fiber.getFiberRef(core.currentMaxOpsBeforeYield) | ||
? fiber.getFiberRef(core.currentSchedulingPriority) | ||
: false | ||
} | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
step() { | ||
@@ -225,2 +258,11 @@ const tasks = this.tasks.buckets | ||
return { | ||
shouldYield(fiber) { | ||
for (const scheduler of record) { | ||
const priority = scheduler[1].shouldYield(fiber) | ||
if (priority !== false) { | ||
return priority | ||
} | ||
} | ||
return false | ||
}, | ||
scheduleTask(task, priority) { | ||
@@ -242,5 +284,21 @@ let scheduler: Scheduler | undefined = undefined | ||
* @since 1.0.0 | ||
* @category utilities | ||
*/ | ||
export const defaultShouldYield: Scheduler["shouldYield"] = (fiber) => { | ||
return fiber.currentOpCount > fiber.getFiberRef(core.currentMaxOpsBeforeYield) | ||
? fiber.getFiberRef(core.currentSchedulingPriority) | ||
: false | ||
} | ||
/** | ||
* @since 1.0.0 | ||
* @category constructors | ||
*/ | ||
export const make = (scheduleTask: Scheduler["scheduleTask"]): Scheduler => ({ scheduleTask }) | ||
export const make = ( | ||
scheduleTask: Scheduler["scheduleTask"], | ||
shouldYield: Scheduler["shouldYield"] = defaultShouldYield | ||
): Scheduler => ({ | ||
scheduleTask, | ||
shouldYield | ||
}) | ||
@@ -251,3 +309,6 @@ /** | ||
*/ | ||
export const makeBatched = (callback: (runBatch: () => void) => void) => { | ||
export const makeBatched = ( | ||
callback: (runBatch: () => void) => void, | ||
shouldYield: Scheduler["shouldYield"] = defaultShouldYield | ||
) => { | ||
let running = false | ||
@@ -278,3 +339,3 @@ const tasks = new PriorityBuckets() | ||
} | ||
}) | ||
}, shouldYield) | ||
} | ||
@@ -286,3 +347,4 @@ | ||
*/ | ||
export const timer = (ms: number) => make((task) => setTimeout(task, ms)) | ||
export const timer = (ms: number, shouldYield: Scheduler["shouldYield"] = defaultShouldYield) => | ||
make((task) => setTimeout(task, ms), shouldYield) | ||
@@ -293,2 +355,15 @@ /** | ||
*/ | ||
export const timerBatched = (ms: number) => makeBatched((task) => setTimeout(task, ms)) | ||
export const timerBatched = (ms: number, shouldYield: Scheduler["shouldYield"] = defaultShouldYield) => | ||
makeBatched((task) => setTimeout(task, ms), shouldYield) | ||
/** @internal */ | ||
export const currentScheduler: FiberRef<Scheduler> = globalValue( | ||
Symbol.for("@effect/io/FiberRef/currentScheduler"), | ||
() => core.fiberRefUnsafeMake(defaultScheduler) | ||
) | ||
/** @internal */ | ||
export const withScheduler = dual< | ||
(scheduler: Scheduler) => <R, E, B>(self: Effect<R, E, B>) => Effect<R, E, B>, | ||
<R, E, B>(self: Effect<R, E, B>, scheduler: Scheduler) => Effect<R, E, B> | ||
>(2, (self, scheduler) => core.fiberRefLocally(self, currentScheduler, scheduler)) |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
6563943
117217