import { Console, Effect, pipe, Random } from 'effect'
const start = Date.now()
console.log('Starting at', start)
type Pending = { _tag: 'Pending' }
type Completed = { _tag: 'Completed' }
const program: Effect.Effect<never, never, Completed> = pipe(
Effect.gen(function* (_) {
const now = Date.now()
yield* _(Console.log('Running at ', now))
return yield* _(
Random.nextIntBetween(0, 100),
Effect.map((num) =>
num < 10
? ({ _tag: 'Completed' } as Completed)
: ({ _tag: 'Pending' } as Pending),
),
)
}),
// How do I repeat the effect at a spaced interval until
// first failure or first success which matches my predicate
// while narrowing the success channel to type `Completed`?
)
Effect.runPromise(program)
import { Console, Effect, pipe, Random } from 'effect'
const start = Date.now()
console.log('Starting at', start)
type Pending = { _tag: 'Pending' }
type Completed = { _tag: 'Completed' }
const program: Effect.Effect<never, never, Completed> = pipe(
Effect.gen(function* (_) {
const now = Date.now()
yield* _(Console.log('Running at ', now))
return yield* _(
Random.nextIntBetween(0, 100),
Effect.map((num) =>
num < 10
? ({ _tag: 'Completed' } as Completed)
: ({ _tag: 'Pending' } as Pending),
),
)
}),
// How do I repeat the effect at a spaced interval until
// first failure or first success which matches my predicate
// while narrowing the success channel to type `Completed`?
)
Effect.runPromise(program)