background
function background<A, E, R>(effect): Effect<BranchHandle<A, E>, never,
Function: background()
function background<A, E, R>(effect): Effect<BranchHandle<A, E>, never,
| Runner
| Exclude<Exclude<R, never>, Phaser>>;Defined in: packages/motion/src/Scene.ts:1206
Like fork, but the animation is CUT OFF at scene end rather than awaited.
Type Parameters
| Type Parameter | Default type |
|---|---|
A | - |
E | never |
R | never |
Parameters
| Parameter | Type | Description |
|---|---|---|
effect | Effect<A, E, R> | The ambient animation. |
Returns
Effect<BranchHandle<A, E>, never,
| Runner
| Exclude<Exclude<R, never>, Phaser>>
A handle with finished and fiber.
Remarks
For ambient motion that should play for as long as the scene lasts
without deciding how long that is — a pulsing indicator, a drifting
backdrop, anything paired with Schedule.forever. A background never
holds the scene open, so the scene's real content governs its length and
the ambient loop simply stops when everything else is done.
"Scene end" includes the fork drain: backgrounds keep animating while awaited forks finish, and are stopped only after the last one.
Because backgrounds do not keep a scene alive, a body that spawns only backgrounds ends immediately and produces NO frames — the background is not content, so there is nothing to give the scene a length. Pair one with something that does define the length, whether a real animation or an explicit sleep, or the ambient motion never gets a frame to play on.
Example
A pulse that runs the whole scene, with the scene's length set by the animation after it.
yield* Scene.background(
Scene.repeat(
pulse.pipe(
Motion.tweenTo({ radius: 24 }, "400 millis"),
Motion.tweenTo({ radius: 10 }, "400 millis"),
),
Schedule.forever,
),
);
yield* title.pipe(Motion.moveTo({ y: 100 }, "2 seconds"));