w2t
TypeScript icon, indicating that this package has built-in type declarations

3.0.2 • Public • Published

w2t

Tiny asynchronous action timer. 150 bytes gzipped.

Install

npm i w2t --save

What is this?

Sometimes UI actions feel more human if we delay them instead of allowing them to be completed at computer time. w2t allows you to specify actions and a minimum time for them to be completed before the Promise is resolved.

If your specified action(s) take longer than the minimum, w2t will wait for all actions to complete before resolving.

Usage

w2t is a thin wrapper around Promise.all, so the API is essentially the same: resolved values are returned on an array, with order preserved.

Below, w2t will resolve foo and baz, but wait 500 ms before returning.

import wait from 'w2t'

const foo = async () => 'bar'
const baz = async () => 'qux'

wait(500, [ foo, baz ]).then(([ resolvedFoo, resolvedBaz ]) => {
  console.log(resolvedFoo, resolveBaz) // 'bar qux'
})

If no actions are provided, w2t becomes useful as a "sleep" function.

// do something

await wait(600)

// do something 600ms later

Changelog

  • v2.0.0 - Typescript rewrite, add tests
  • v1.0.0 - initial release

License

MIT License © Eric Bailey

Readme

Keywords

none

Package Sidebar

Install

npm i w2t

Weekly Downloads

174

Version

3.0.2

License

MIT

Unpacked Size

8.6 kB

Total Files

6

Last publish

Collaborators

  • estrattonbailey