Effect TS · Reference

Schedules & retries — cheatsheet

The compressed lesson: every builder, combinator, and rule for "try again" and "don't wait forever". Effect 3.22.1, behaviours verified in the course sandbox.

The shape

Schedule = // a value describing when/how often to act again

Effect.retry(effect, policy)      // loop on E-channel failures
Effect.retryOrElse(effect, policy, orElse) // fall back after exhaustion
Effect.timeout(effect, '200 millis')       // cap the wait

Builders

BuilderPlan it makesVerified note
Schedule.recurs(n)Stop after n retriesCounts retries, not attempts: n retries = n+1 attempts
Schedule.onceRetry oncePre-built value — no parentheses
Schedule.foreverNever stopPre-built value — pair it with a cap
Schedule.spaced(d)Wait d after each finish, then try againUnbounded alone
Schedule.fixed(d)New try every d, regardless of attempt lengthSteady cadence
Schedule.exponential(base, factor)base, base×factor, base×factor², …Measured 10+20+40ms for 3 retries at ('10 millis', 2)
Schedule.jittered(s)s with randomised delaysSpreads load when many callers retry together

Composing

CombinatorRuleVerified example
Schedule.intersect(a, b)The tighter plan wins (cap and delay both apply)intersect(recurs(5), spaced('50ms')) — the production recipe
Schedule.union(a, b)Keep going while either allows — the longer winsunion(recurs(2), recurs(5)) → 5 retries
Schedule.andThen(a, b)Run plan a to exhaustion, then plan bUseful for "fast retries, then slow ones"

Shorthands & conditions

FormUse whenNotes
Effect.retry(effect, { times: 5 })Quick cap, no waitingObject shorthand for Effect.retry only
Effect.retry(effect, { until: f })Stop retrying when f(error) is trueAlso while; docs form 1
Effect.retryOrElse(effect, policy, orElse)Plan B after exhaustionVerified with a real Schedule; orElse receives the final error
Effect.repeat(effect, policy)Repeat on successesMirror of retry; stops at first failure 2
Effect.timeout(effect, d)Cap the wait at dLoss → TimeoutException failure; abandon the slow work

BullMQ → Effect translation

You wrote (BullMQ ops)Effect equivalent
withRetry loop, delay *= 2Effect.retry(e, Schedule.exponential('100 millis', 2))
attempts: 5 job optionSchedule.recurs(5) — or { times: 5 } — capped via intersect
backoff: { type: 'fixed', delay }Schedule.spaced(delay) (after each finish) / Schedule.fixed(delay) (steady cadence)
Per-site copies of the loopOne policy value, passed/attached per call site
Timeout guard around a workerEffect.timeout + catchTag('TimeoutException', fallback)

Rules of thumb

Full API

Everything else (filtering, adjusting delays, driving schedules by hand) lives in the Schedule module API reference; retry forms in the Retrying guide.

← Back to Lesson 3