0.1.0 • Published 9 months ago

@promistream/timer v0.1.0

Weekly downloads
-
License
WTFPL OR CC0-1.0
Repository
-
Last release
9 months ago

timer

Source stream that emits a value repeatedly at a fixed interval.

Unfamiliar with Promistreams?

Promistreams are universal, composable streams that interoperate with other streaming systems such as Node streams and asynchronous generators.

Have a look at the Promistream documentation to learn more about how they work, and how to use them!

Example

See the example.js in the repository/package.

Semantics

Every time a new value is requested from this stream, one of three things happens:

  1. A previous request is still waiting to receive a value, and the new request is queued behind it, and only made once the previous request has been fulfilled, or
  2. If the interval has elapsed since the last time a value was emitted, the hardcoded value is emitted immediately, or
  3. If the interval has not yet elapsed since the last time, the stream waits until it has, and then emits the hardcoded value.

In practice, this means that a value is emitted at a fixed interval, if you are continuously requesting new values from the stream. If it takes a long time before you make the next request due to eg. processing delays (longer than the interval itself), then that means that it will be immediately fulfilled upon the next call, but the total interval between the two values would have been more than the configured interval. Therefore, you should treat the interval as an 'at least' value.

API

timer(options)

Returns a new source stream that emits the specified value every interval.

  • options: - interval: An interval in either milliseconds (as a number) or as an ms-compatible input such as "2h". - value: The value to emit each time.