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

Function toStepWithMetadata

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

Source from the content-addressed store, hash-verified

375 * @since 4.0.0
376 */
377export const toStepWithMetadata = <Output, Input, Error, Env>(
378 schedule: Schedule<Output, Input, Error, Env>
379): Effect<
380 (input: Input) => Pull.Pull<Metadata<Output, Input>, Error, Output, Env>,
381 never,
382 Env
383> =>
384 effect.clockWith((clock) =>
385 effect.map(
386 toStep(schedule),
387 (step) => {
388 const metaFn = metadataFn()
389 return (input) =>
390 effect.suspend(() => {
391 const now = clock.currentTimeMillisUnsafe()
392 return effect.flatMap(
393 step(now, input),
394 ([output, duration]) => {
395 const meta = metaFn(now, input) as Mutable<Metadata<Output, Input>>
396 meta.output = output
397 meta.duration = duration
398 return effect.as(effect.sleep(duration), meta)
399 }
400 )
401 })
402 }
403 )
404 )
405
406/**
407 * 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