Skip to main content

AtomInstanceTtl

TTL (Time To Live) can be set at the ecosystem, atom template, or atom instance levels. Setting a ttl at the atom instance level is the most specific and the most flexible. You can do so using an AtomApi.

A ttl set on an atom instance overrides any ttl on its atom template or ecosystem. A ttl set on an atom template overrides any atomDefaults.ttl on the ecosystem.

Definition

type AtomInstanceTtl = number | Promise<any> | Observable<any>

Note that the .ttl property of an AtomApi can also be a function that returns any of these.

This is far more flexible than ecosystem- and atom-template-level ttl, which can only be a number.

  • When a number is set, Zedux will set a timeout for <ttl> milliseconds. When that timeout times out, Zedux will clean up the atom instance. A ttl of 0 will skip the timeout and clean up immediately.
  • When a promise is set, Zedux will wait for that promise to resolve before cleaning up the atom instance.
  • When an observable is set, Zedux will wait for that observable to emit before cleaning up the atom instance.

In all cases, if the atom instance is used again while Zedux is awaiting the ok for cleanup, cleanup will be cancelled; The instance's status will transition from Stale back to Active.