MCPcopy Create free account
hub / github.com/Effect-TS/effect / toStepWithMetadata

Function toStepWithMetadata

packages/effect/src/Schedule.ts:392–419  ·  view source on GitHub ↗
(
  schedule: Schedule<Output, Input, Error, Env>
)

Source from the content-addressed store, hash-verified

390 * @since 4.0.0
391 */
392export const toStepWithMetadata = <Output, Input, Error, Env>(
393 schedule: Schedule<Output, Input, Error, Env>
394): Effect<
395 (input: Input) => Pull.Pull<Metadata<Output, Input>, Error, Output, Env>,
396 never,
397 Env
398> =>
399 effect.clockWith((clock) =>
400 effect.map(
401 toStep(schedule),
402 (step) => {
403 const metaFn = metadataFn()
404 return (input) =>
405 effect.suspend(() => {
406 const now = clock.currentTimeMillisUnsafe()
407 return effect.flatMap(
408 step(now, input),
409 ([output, duration]) => {
410 const meta = metaFn(now, input) as Mutable<Metadata<Output, Input>>
411 meta.output = output
412 meta.duration = duration
413 return effect.as(effect.sleep(duration), meta)
414 }
415 )
416 })
417 }
418 )
419 )
420
421/**
422 * Extracts a step function from a Schedule that automatically handles sleep delays.

Callers 1

toStepWithSleepFunction · 0.85

Calls 6

toStepFunction · 0.85
metadataFnFunction · 0.85
stepFunction · 0.70
sleepMethod · 0.65
mapMethod · 0.45

Tested by

no test coverage detected