effect 3.3.4 → 3.3.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/dist/cjs/Config.js.map +1 -1
- package/dist/cjs/Effect.js +145 -21
- package/dist/cjs/Effect.js.map +1 -1
- package/dist/cjs/internal/version.js +1 -1
- package/dist/dts/Config.d.ts +3 -4
- package/dist/dts/Config.d.ts.map +1 -1
- package/dist/dts/Effect.d.ts +145 -21
- package/dist/dts/Effect.d.ts.map +1 -1
- package/dist/esm/Config.js.map +1 -1
- package/dist/esm/Effect.js +145 -21
- package/dist/esm/Effect.js.map +1 -1
- package/dist/esm/internal/version.js +1 -1
- package/package.json +1 -1
- package/src/Config.ts +7 -5
- package/src/Effect.ts +145 -21
- package/src/internal/version.ts +1 -1
package/dist/dts/Effect.d.ts
CHANGED
|
@@ -228,8 +228,38 @@ export declare namespace Effect {
|
|
|
228
228
|
*/
|
|
229
229
|
export declare const isEffect: (u: unknown) => u is Effect<unknown, unknown, unknown>;
|
|
230
230
|
/**
|
|
231
|
-
* Returns an effect that
|
|
232
|
-
*
|
|
231
|
+
* Returns an effect that caches its result for a specified duration, known as
|
|
232
|
+
* the `timeToLive`. When the cache expires after the duration, the effect will be
|
|
233
|
+
* recomputed upon next evaluation.
|
|
234
|
+
*
|
|
235
|
+
* @example
|
|
236
|
+
* import { Effect, Console } from "effect"
|
|
237
|
+
*
|
|
238
|
+
* let i = 1
|
|
239
|
+
* const expensiveTask = Effect.promise<string>(() => {
|
|
240
|
+
* console.log("expensive task...")
|
|
241
|
+
* return new Promise((resolve) => {
|
|
242
|
+
* setTimeout(() => {
|
|
243
|
+
* resolve(`result ${i++}`)
|
|
244
|
+
* }, 100)
|
|
245
|
+
* })
|
|
246
|
+
* })
|
|
247
|
+
*
|
|
248
|
+
* const program = Effect.gen(function* () {
|
|
249
|
+
* const cached = yield* Effect.cachedWithTTL(expensiveTask, "150 millis")
|
|
250
|
+
* yield* cached.pipe(Effect.andThen(Console.log))
|
|
251
|
+
* yield* cached.pipe(Effect.andThen(Console.log))
|
|
252
|
+
* yield* Effect.sleep("100 millis")
|
|
253
|
+
* yield* cached.pipe(Effect.andThen(Console.log))
|
|
254
|
+
* })
|
|
255
|
+
*
|
|
256
|
+
* // Effect.runFork(program)
|
|
257
|
+
* // Output:
|
|
258
|
+
* // expensive task...
|
|
259
|
+
* // result 1
|
|
260
|
+
* // result 1
|
|
261
|
+
* // expensive task...
|
|
262
|
+
* // result 2
|
|
233
263
|
*
|
|
234
264
|
* @since 2.0.0
|
|
235
265
|
* @category caching
|
|
@@ -239,10 +269,41 @@ export declare const cachedWithTTL: {
|
|
|
239
269
|
<A, E, R>(self: Effect<A, E, R>, timeToLive: Duration.DurationInput): Effect<Effect<A, E>, never, R>;
|
|
240
270
|
};
|
|
241
271
|
/**
|
|
242
|
-
*
|
|
243
|
-
*
|
|
244
|
-
*
|
|
245
|
-
*
|
|
272
|
+
* Similar to {@link cachedWithTTL}, this function caches an effect's result for a
|
|
273
|
+
* specified duration. It also includes an additional effect for manually
|
|
274
|
+
* invalidating the cached value before it naturally expires.
|
|
275
|
+
*
|
|
276
|
+
* @example
|
|
277
|
+
* import { Effect, Console } from "effect"
|
|
278
|
+
*
|
|
279
|
+
* let i = 1
|
|
280
|
+
* const expensiveTask = Effect.promise<string>(() => {
|
|
281
|
+
* console.log("expensive task...")
|
|
282
|
+
* return new Promise((resolve) => {
|
|
283
|
+
* setTimeout(() => {
|
|
284
|
+
* resolve(`result ${i++}`)
|
|
285
|
+
* }, 100)
|
|
286
|
+
* })
|
|
287
|
+
* })
|
|
288
|
+
*
|
|
289
|
+
* const program = Effect.gen(function* () {
|
|
290
|
+
* const [cached, invalidate] = yield* Effect.cachedInvalidateWithTTL(
|
|
291
|
+
* expensiveTask,
|
|
292
|
+
* "1 hour"
|
|
293
|
+
* )
|
|
294
|
+
* yield* cached.pipe(Effect.andThen(Console.log))
|
|
295
|
+
* yield* cached.pipe(Effect.andThen(Console.log))
|
|
296
|
+
* yield* invalidate
|
|
297
|
+
* yield* cached.pipe(Effect.andThen(Console.log))
|
|
298
|
+
* })
|
|
299
|
+
*
|
|
300
|
+
* // Effect.runFork(program)
|
|
301
|
+
* // Output:
|
|
302
|
+
* // expensive task...
|
|
303
|
+
* // result 1
|
|
304
|
+
* // result 1
|
|
305
|
+
* // expensive task...
|
|
306
|
+
* // result 2
|
|
246
307
|
*
|
|
247
308
|
* @since 2.0.0
|
|
248
309
|
* @category caching
|
|
@@ -252,39 +313,102 @@ export declare const cachedInvalidateWithTTL: {
|
|
|
252
313
|
<A, E, R>(self: Effect<A, E, R>, timeToLive: Duration.DurationInput): Effect<[Effect<A, E>, Effect<void>], never, R>;
|
|
253
314
|
};
|
|
254
315
|
/**
|
|
255
|
-
* Returns an effect that
|
|
256
|
-
*
|
|
316
|
+
* Returns an effect that computes a result lazily and caches it. Subsequent
|
|
317
|
+
* evaluations of this effect will return the cached result without re-executing
|
|
318
|
+
* the logic.
|
|
319
|
+
*
|
|
320
|
+
* @example
|
|
321
|
+
* import { Effect, Console } from "effect"
|
|
322
|
+
*
|
|
323
|
+
* let i = 1
|
|
324
|
+
* const expensiveTask = Effect.promise<string>(() => {
|
|
325
|
+
* console.log("expensive task...")
|
|
326
|
+
* return new Promise((resolve) => {
|
|
327
|
+
* setTimeout(() => {
|
|
328
|
+
* resolve(`result ${i++}`)
|
|
329
|
+
* }, 100)
|
|
330
|
+
* })
|
|
331
|
+
* })
|
|
332
|
+
*
|
|
333
|
+
* const program = Effect.gen(function* () {
|
|
334
|
+
* console.log("non-cached version:")
|
|
335
|
+
* yield* expensiveTask.pipe(Effect.andThen(Console.log))
|
|
336
|
+
* yield* expensiveTask.pipe(Effect.andThen(Console.log))
|
|
337
|
+
* console.log("cached version:")
|
|
338
|
+
* const cached = yield* Effect.cached(expensiveTask)
|
|
339
|
+
* yield* cached.pipe(Effect.andThen(Console.log))
|
|
340
|
+
* yield* cached.pipe(Effect.andThen(Console.log))
|
|
341
|
+
* })
|
|
342
|
+
*
|
|
343
|
+
* // Effect.runFork(program)
|
|
344
|
+
* // Output:
|
|
345
|
+
* // non-cached version:
|
|
346
|
+
* // expensive task...
|
|
347
|
+
* // result 1
|
|
348
|
+
* // expensive task...
|
|
349
|
+
* // result 2
|
|
350
|
+
* // cached version:
|
|
351
|
+
* // expensive task...
|
|
352
|
+
* // result 3
|
|
353
|
+
* // result 3
|
|
257
354
|
*
|
|
258
355
|
* @since 2.0.0
|
|
259
356
|
* @category caching
|
|
260
357
|
*/
|
|
261
358
|
export declare const cached: <A, E, R>(self: Effect<A, E, R>) => Effect<Effect<A, E, R>>;
|
|
262
359
|
/**
|
|
263
|
-
* Returns a memoized version of
|
|
360
|
+
* Returns a memoized version of a function with effects. Memoization ensures
|
|
361
|
+
* that results are stored and reused for the same inputs, reducing the need to
|
|
362
|
+
* recompute them.
|
|
363
|
+
*
|
|
364
|
+
* @example
|
|
365
|
+
* import { Effect, Random } from "effect"
|
|
366
|
+
*
|
|
367
|
+
* const program = Effect.gen(function* () {
|
|
368
|
+
* const randomNumber = (n: number) => Random.nextIntBetween(1, n)
|
|
369
|
+
* console.log("non-memoized version:")
|
|
370
|
+
* console.log(yield* randomNumber(10))
|
|
371
|
+
* console.log(yield* randomNumber(10))
|
|
372
|
+
*
|
|
373
|
+
* console.log("memoized version:")
|
|
374
|
+
* const memoized = yield* Effect.cachedFunction(randomNumber)
|
|
375
|
+
* console.log(yield* memoized(10))
|
|
376
|
+
* console.log(yield* memoized(10))
|
|
377
|
+
* })
|
|
378
|
+
*
|
|
379
|
+
* // Effect.runFork(program)
|
|
380
|
+
* // Example Output:
|
|
381
|
+
* // non-memoized version:
|
|
382
|
+
* // 2
|
|
383
|
+
* // 8
|
|
384
|
+
* // memoized version:
|
|
385
|
+
* // 5
|
|
386
|
+
* // 5
|
|
264
387
|
*
|
|
265
388
|
* @since 2.0.0
|
|
266
389
|
* @category caching
|
|
267
390
|
*/
|
|
268
391
|
export declare const cachedFunction: <A, B, E, R>(f: (a: A) => Effect<B, E, R>, eq?: Equivalence<A>) => Effect<(a: A) => Effect<B, E, R>>;
|
|
269
392
|
/**
|
|
270
|
-
* Returns an effect that
|
|
271
|
-
*
|
|
393
|
+
* Returns an effect that executes only once, regardless of how many times it's
|
|
394
|
+
* called.
|
|
272
395
|
*
|
|
273
396
|
* @example
|
|
274
397
|
* import { Effect, Console } from "effect"
|
|
275
398
|
*
|
|
276
|
-
* const program = Effect.gen(function* (
|
|
277
|
-
* const
|
|
278
|
-
* yield*
|
|
279
|
-
* const
|
|
280
|
-
* yield*
|
|
399
|
+
* const program = Effect.gen(function* () {
|
|
400
|
+
* const task1 = Console.log("task1")
|
|
401
|
+
* yield* Effect.repeatN(task1, 2)
|
|
402
|
+
* const task2 = yield* Effect.once(Console.log("task2"))
|
|
403
|
+
* yield* Effect.repeatN(task2, 2)
|
|
281
404
|
* })
|
|
282
405
|
*
|
|
283
|
-
* Effect.runFork(program)
|
|
406
|
+
* // Effect.runFork(program)
|
|
284
407
|
* // Output:
|
|
285
|
-
* //
|
|
286
|
-
* //
|
|
287
|
-
* //
|
|
408
|
+
* // task1
|
|
409
|
+
* // task1
|
|
410
|
+
* // task1
|
|
411
|
+
* // task2
|
|
288
412
|
*
|
|
289
413
|
* @since 2.0.0
|
|
290
414
|
* @category caching
|
|
@@ -1758,7 +1882,7 @@ export declare const scope: Effect<Scope.Scope, never, Scope.Scope>;
|
|
|
1758
1882
|
*/
|
|
1759
1883
|
export declare const scopeWith: <A, E, R>(f: (scope: Scope.Scope) => Effect<A, E, R>) => Effect<A, E, R | Scope.Scope>;
|
|
1760
1884
|
/**
|
|
1761
|
-
* Scopes all resources
|
|
1885
|
+
* Scopes all resources used in this workflow to the lifetime of the workflow,
|
|
1762
1886
|
* ensuring that their finalizers are run as soon as this workflow completes
|
|
1763
1887
|
* execution, whether by success, failure, or interruption.
|
|
1764
1888
|
*
|