@effect/io
Advanced tools
Comparing version 0.28.0 to 0.29.0
@@ -35,2 +35,10 @@ /** | ||
/** | ||
* Unsafely returns the current time in nanoseconds. | ||
*/ | ||
unsafeCurrentTimeNanos(): bigint; | ||
/** | ||
* Returns the current time in nanoseconds. | ||
*/ | ||
currentTimeNanos(): Effect.Effect<never, never, bigint>; | ||
/** | ||
* Asynchronously sleeps for the specified duration. | ||
@@ -79,2 +87,7 @@ */ | ||
*/ | ||
export declare const currentTimeNanos: (_: void) => Effect.Effect<never, never, bigint>; | ||
/** | ||
* @since 1.0.0 | ||
* @category constructors | ||
*/ | ||
export declare const clockWith: <R, E, A>(f: (clock: Clock) => Effect.Effect<R, E, A>) => Effect.Effect<R, E, A>; | ||
@@ -81,0 +94,0 @@ /** |
@@ -6,3 +6,3 @@ "use strict"; | ||
}); | ||
exports.sleep = exports.make = exports.currentTimeMillis = exports.clockWith = exports.ClockTypeId = exports.Clock = void 0; | ||
exports.sleep = exports.make = exports.currentTimeNanos = exports.currentTimeMillis = exports.clockWith = exports.ClockTypeId = exports.Clock = void 0; | ||
var internal = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/io/internal_effect_untraced/clock")); | ||
@@ -40,2 +40,8 @@ var defaultServices = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/io/internal_effect_untraced/defaultServices")); | ||
exports.currentTimeMillis = currentTimeMillis; | ||
const currentTimeNanos = defaultServices.currentTimeNanos; | ||
/** | ||
* @since 1.0.0 | ||
* @category constructors | ||
*/ | ||
exports.currentTimeNanos = currentTimeNanos; | ||
const clockWith = defaultServices.clockWith; | ||
@@ -42,0 +48,0 @@ /** |
@@ -284,3 +284,3 @@ /** | ||
*/ | ||
export declare const currentTracerSpanAnnotations: FiberRef<HashMap.HashMap<string, string>>; | ||
export declare const currentTracerSpanAnnotations: FiberRef<HashMap.HashMap<string, Tracer.AttributeValue>>; | ||
/** | ||
@@ -287,0 +287,0 @@ * @since 1.0.0 |
@@ -54,5 +54,11 @@ "use strict"; | ||
} | ||
unsafeCurrentTimeNanos() { | ||
return BigInt(Math.round(performance.timeOrigin * 1000000)) + BigInt(Math.round(performance.now() * 1000000)); | ||
} | ||
currentTimeMillis() { | ||
return Debug.bodyWithTrace(trace => core.sync(() => this.unsafeCurrentTimeMillis()).traced(trace)); | ||
} | ||
currentTimeNanos() { | ||
return Debug.bodyWithTrace(trace => core.sync(() => this.unsafeCurrentTimeNanos()).traced(trace)); | ||
} | ||
scheduler() { | ||
@@ -59,0 +65,0 @@ return Debug.bodyWithTrace(trace => core.succeed(globalClockScheduler).traced(trace)); |
@@ -6,3 +6,3 @@ "use strict"; | ||
}); | ||
exports.withTracer = exports.withConfigProvider = exports.withClock = exports.tracerWith = exports.sleep = exports.shuffle = exports.randomWith = exports.nextRange = exports.nextIntBetween = exports.nextInt = exports.nextBoolean = exports.next = exports.liveServices = exports.currentTimeMillis = exports.currentServices = exports.configProviderWith = exports.configOrDie = exports.config = exports.clockWith = void 0; | ||
exports.withTracer = exports.withConfigProvider = exports.withClock = exports.tracerWith = exports.sleep = exports.shuffle = exports.randomWith = exports.nextRange = exports.nextIntBetween = exports.nextInt = exports.nextBoolean = exports.next = exports.liveServices = exports.currentTimeNanos = exports.currentTimeMillis = exports.currentServices = exports.configProviderWith = exports.configOrDie = exports.config = exports.clockWith = void 0; | ||
var Context = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/data/Context")); | ||
@@ -33,2 +33,5 @@ var Debug = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/data/Debug")); | ||
exports.currentTimeMillis = currentTimeMillis; | ||
const currentTimeNanos = /*#__PURE__*/Debug.methodWithTrace(trace => () => clockWith(clock => clock.currentTimeNanos()).traced(trace)); | ||
/** @internal */ | ||
exports.currentTimeNanos = currentTimeNanos; | ||
const sleep = /*#__PURE__*/Debug.methodWithTrace(trace => duration => clockWith(clock => clock.sleep(duration)).traced(trace)); | ||
@@ -35,0 +38,0 @@ /** @internal */ |
@@ -81,3 +81,3 @@ "use strict"; | ||
Error.stackTraceLimit = limit; | ||
const message = `Fiber #${fiber.id().id} has suspended work asyncroniously`; | ||
const message = `Fiber #${fiber.id().id} has suspended work asynchronously`; | ||
const _tag = "AsyncFiberException"; | ||
@@ -84,0 +84,0 @@ Object.defineProperties(error, { |
@@ -75,2 +75,14 @@ "use strict"; | ||
/** | ||
* Unsafely returns the current time in nanoseconds. | ||
*/ | ||
unsafeCurrentTimeNanos() { | ||
return BigInt(ref.unsafeGet(this.clockState).instant * 1000000); | ||
} | ||
/** | ||
* Returns the current clock time in nanoseconds. | ||
*/ | ||
currentTimeNanos() { | ||
return Debug.bodyWithTrace(trace => core.map(ref.get(this.clockState), data => BigInt(data.instant * 1000000)).traced(trace)); | ||
} | ||
/** | ||
* Saves the `TestClock`'s current state in an effect which, when run, will | ||
@@ -77,0 +89,0 @@ * restore the `TestClock` state to the saved state. |
@@ -39,5 +39,6 @@ "use strict"; | ||
class NativeSpan { | ||
constructor(name, parent, startTime) { | ||
constructor(name, parent, context, startTime) { | ||
this.name = name; | ||
this.parent = parent; | ||
this.context = context; | ||
this.startTime = startTime; | ||
@@ -72,3 +73,3 @@ this._tag = "Span"; | ||
const nativeTracer = /*#__PURE__*/make({ | ||
span: (name, parent, startTime) => new NativeSpan(name, parent, startTime) | ||
span: (name, parent, traceFlags, startTime) => new NativeSpan(name, parent, traceFlags, startTime) | ||
}); | ||
@@ -75,0 +76,0 @@ /** @internal */ |
{ | ||
"name": "@effect/io", | ||
"version": "0.28.0", | ||
"version": "0.29.0", | ||
"license": "MIT", | ||
@@ -5,0 +5,0 @@ "repository": { |
@@ -40,2 +40,10 @@ /** | ||
/** | ||
* Unsafely returns the current time in nanoseconds. | ||
*/ | ||
unsafeCurrentTimeNanos(): bigint | ||
/** | ||
* Returns the current time in nanoseconds. | ||
*/ | ||
currentTimeNanos(): Effect.Effect<never, never, bigint> | ||
/** | ||
* Asynchronously sleeps for the specified duration. | ||
@@ -91,2 +99,8 @@ */ | ||
*/ | ||
export const currentTimeNanos: (_: void) => Effect.Effect<never, never, bigint> = defaultServices.currentTimeNanos | ||
/** | ||
* @since 1.0.0 | ||
* @category constructors | ||
*/ | ||
export const clockWith: <R, E, A>(f: (clock: Clock) => Effect.Effect<R, E, A>) => Effect.Effect<R, E, A> = | ||
@@ -93,0 +107,0 @@ defaultServices.clockWith |
@@ -371,3 +371,4 @@ /** | ||
*/ | ||
export const currentTracerSpanAnnotations: FiberRef<HashMap.HashMap<string, string>> = core.currentTracerSpanAnnotations | ||
export const currentTracerSpanAnnotations: FiberRef<HashMap.HashMap<string, Tracer.AttributeValue>> = | ||
core.currentTracerSpanAnnotations | ||
@@ -374,0 +375,0 @@ /** |
@@ -50,2 +50,6 @@ import * as Context from "@effect/data/Context" | ||
unsafeCurrentTimeNanos(): bigint { | ||
return BigInt(Math.round(performance.timeOrigin * 1000000)) + BigInt(Math.round(performance.now() * 1000000)) | ||
} | ||
currentTimeMillis(): Effect.Effect<never, never, number> { | ||
@@ -55,2 +59,6 @@ return Debug.bodyWithTrace((trace) => core.sync(() => this.unsafeCurrentTimeMillis()).traced(trace)) | ||
currentTimeNanos(): Effect.Effect<never, never, bigint> { | ||
return Debug.bodyWithTrace((trace) => core.sync(() => this.unsafeCurrentTimeNanos()).traced(trace)) | ||
} | ||
scheduler(): Effect.Effect<never, never, Clock.ClockScheduler> { | ||
@@ -57,0 +65,0 @@ return Debug.bodyWithTrace((trace) => core.succeed(globalClockScheduler).traced(trace)) |
@@ -44,2 +44,7 @@ import type * as Chunk from "@effect/data/Chunk" | ||
/** @internal */ | ||
export const currentTimeNanos = Debug.methodWithTrace((trace) => | ||
(): Effect.Effect<never, never, bigint> => clockWith((clock) => clock.currentTimeNanos()).traced(trace) | ||
) | ||
/** @internal */ | ||
export const sleep = Debug.methodWithTrace((trace) => | ||
@@ -46,0 +51,0 @@ (duration: Duration.Duration): Effect.Effect<never, never, void> => |
@@ -126,3 +126,3 @@ import * as Context from "@effect/data/Context" | ||
Error.stackTraceLimit = limit | ||
const message = `Fiber #${fiber.id().id} has suspended work asyncroniously` | ||
const message = `Fiber #${fiber.id().id} has suspended work asynchronously` | ||
const _tag = "AsyncFiberException" | ||
@@ -129,0 +129,0 @@ Object.defineProperties(error, { |
@@ -139,3 +139,23 @@ import * as Chunk from "@effect/data/Chunk" | ||
} | ||
/** | ||
* Unsafely returns the current time in nanoseconds. | ||
*/ | ||
unsafeCurrentTimeNanos(): bigint { | ||
return BigInt(ref.unsafeGet(this.clockState).instant * 1000000) | ||
} | ||
/** | ||
* Returns the current clock time in nanoseconds. | ||
*/ | ||
currentTimeNanos(): Effect.Effect<never, never, bigint> { | ||
return Debug.bodyWithTrace((trace) => | ||
core.map( | ||
ref.get(this.clockState), | ||
(data) => BigInt(data.instant * 1000000) | ||
).traced(trace) | ||
) | ||
} | ||
/** | ||
* Saves the `TestClock`'s current state in an effect which, when run, will | ||
@@ -142,0 +162,0 @@ * restore the `TestClock` state to the saved state. |
@@ -41,4 +41,4 @@ /** | ||
status: Tracer.SpanStatus | ||
attributes: Map<string, string> | ||
events: Array<[name: string, attributes: Record<string, string>]> = [] | ||
attributes: Map<string, Tracer.AttributeValue> | ||
events: Array<[name: string, attributes: Record<string, Tracer.AttributeValue>]> = [] | ||
@@ -48,3 +48,4 @@ constructor( | ||
readonly parent: Option.Option<Tracer.ParentSpan>, | ||
readonly startTime: number | ||
readonly context: Context.Context<never>, | ||
readonly startTime: bigint | ||
) { | ||
@@ -59,3 +60,3 @@ this.status = { | ||
end = (endTime: number, exit: Exit.Exit<unknown, unknown>): void => { | ||
end = (endTime: bigint, exit: Exit.Exit<unknown, unknown>): void => { | ||
this.status = { | ||
@@ -69,7 +70,7 @@ _tag: "Ended", | ||
attribute = (key: string, value: string): void => { | ||
attribute = (key: string, value: Tracer.AttributeValue): void => { | ||
this.attributes.set(key, value) | ||
} | ||
event = (name: string, attributes?: Record<string, string>): void => { | ||
event = (name: string, attributes?: Record<string, Tracer.AttributeValue>): void => { | ||
this.events.push([name, attributes ?? {}]) | ||
@@ -81,3 +82,3 @@ } | ||
export const nativeTracer: Tracer.Tracer = make({ | ||
span: (name, parent, startTime) => new NativeSpan(name, parent, startTime) | ||
span: (name, parent, traceFlags, startTime) => new NativeSpan(name, parent, traceFlags, startTime) | ||
}) | ||
@@ -84,0 +85,0 @@ |
@@ -27,3 +27,8 @@ /** | ||
readonly [TracerTypeId]: TracerTypeId | ||
readonly span: (name: string, parent: Option.Option<ParentSpan>, startTime: number) => Span | ||
readonly span: ( | ||
name: string, | ||
parent: Option.Option<ParentSpan>, | ||
context: Context.Context<never>, | ||
startTime: bigint | ||
) => Span | ||
} | ||
@@ -37,7 +42,7 @@ | ||
_tag: "Started" | ||
startTime: number | ||
startTime: bigint | ||
} | { | ||
_tag: "Ended" | ||
startTime: number | ||
endTime: number | ||
startTime: bigint | ||
endTime: bigint | ||
exit: Exit.Exit<unknown, unknown> | ||
@@ -61,2 +66,3 @@ } | ||
readonly traceId: string | ||
readonly context: Context.Context<never> | ||
} | ||
@@ -74,8 +80,14 @@ | ||
readonly parent: Option.Option<ParentSpan> | ||
readonly context: Context.Context<never> | ||
readonly status: SpanStatus | ||
readonly attributes: ReadonlyMap<string, string> | ||
readonly end: (endTime: number, exit: Exit.Exit<unknown, unknown>) => void | ||
readonly attribute: (key: string, value: string) => void | ||
readonly event: (name: string, attributes?: Record<string, string>) => void | ||
readonly attributes: ReadonlyMap<string, AttributeValue> | ||
readonly end: (endTime: bigint, exit: Exit.Exit<unknown, unknown>) => void | ||
readonly attribute: (key: string, value: AttributeValue) => void | ||
readonly event: (name: string, attributes?: Record<string, AttributeValue>) => void | ||
} | ||
/** | ||
* @since 1.0.0 | ||
* @category models | ||
*/ | ||
export type AttributeValue = string | boolean | number | ||
@@ -82,0 +94,0 @@ /** |
@@ -22,3 +22,3 @@ /** | ||
readonly [TracerTypeId]: TracerTypeId; | ||
readonly span: (name: string, parent: Option.Option<ParentSpan>, startTime: number) => Span; | ||
readonly span: (name: string, parent: Option.Option<ParentSpan>, context: Context.Context<never>, startTime: bigint) => Span; | ||
} | ||
@@ -31,7 +31,7 @@ /** | ||
_tag: "Started"; | ||
startTime: number; | ||
startTime: bigint; | ||
} | { | ||
_tag: "Ended"; | ||
startTime: number; | ||
endTime: number; | ||
startTime: bigint; | ||
endTime: bigint; | ||
exit: Exit.Exit<unknown, unknown>; | ||
@@ -53,2 +53,3 @@ }; | ||
readonly traceId: string; | ||
readonly context: Context.Context<never>; | ||
} | ||
@@ -65,10 +66,16 @@ /** | ||
readonly parent: Option.Option<ParentSpan>; | ||
readonly context: Context.Context<never>; | ||
readonly status: SpanStatus; | ||
readonly attributes: ReadonlyMap<string, string>; | ||
readonly end: (endTime: number, exit: Exit.Exit<unknown, unknown>) => void; | ||
readonly attribute: (key: string, value: string) => void; | ||
readonly event: (name: string, attributes?: Record<string, string>) => void; | ||
readonly attributes: ReadonlyMap<string, AttributeValue>; | ||
readonly end: (endTime: bigint, exit: Exit.Exit<unknown, unknown>) => void; | ||
readonly attribute: (key: string, value: AttributeValue) => void; | ||
readonly event: (name: string, attributes?: Record<string, AttributeValue>) => void; | ||
} | ||
/** | ||
* @since 1.0.0 | ||
* @category models | ||
*/ | ||
export type AttributeValue = string | boolean | number; | ||
/** | ||
* @since 1.0.0 | ||
* @category tags | ||
@@ -75,0 +82,0 @@ */ |
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 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 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 not supported yet
Sorry, the diff of this file is not supported yet
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
6953192
119307