Skip to content

0.9.2

Choose a tag to compare

@realpha realpha released this 28 Jan 22:04
· 5 commits to main since this release
170768c

Features

  • Task.deferred(): This new static factory method allows for the creation of a deferred Task<T, E>. This may come in handy when working with push-based APIs such as EventTarget or when trying to emulate a timeout-behaviour, e.g:
class TimeoutError extends Error {}

const { task, succeed, fail } = Task.deferred<number, TimeoutError>();

const okTimerId = setTimeout(() => succeed(21), Math.random() * 1000);
const errTimerId = setTimeout(() => fail(new TimeoutError()), Math.randon() * 1000);
const timers = [ okTimerId, errTimerId ];

task
  .map((n) => n * 2)
  .inspect(console.log)
  .inspectErr(console.error)
  .finally(() => timers.forEach((id) => clearTimeout(id)) )

Fixes


Misc

  • As the implementation of Task.deferred() is not dependent upon the new Promise.withResolvers() method, this change is fully backwards compatible, also with regards to the minimum supported runtime versions.

Changes

  • feat(task): create deferred task by @realpha in #31
  • fix(ci): pin deno version in release workflow by @realpha in #32
  • feat(task): made deferred backwards compatible with version constraints by @realpha in #33

Full Changelog: 0.8.0...0.9.2