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

1.0.0 • Public • Published

timethen

Very small async timeout.

Three lines of code. Without promises, classes, constructors, etc...

Usage

import timethen from 'timethen';
// or const timethen = require('timethen').default



;(async () => {
  console.log('start func')

  await timethen(1000) // pause in 1 sec

  console.log('after 1 sec')
})()



// or so
timethen(2000, 'val')
  .then((val) => {
    console.log('in two seconds:', val) // in two seconds: val
  })
// !Only one "then"!


// or so
// If you need a chain of "thens"
Promise.resolve(timethen(2000, 'Hello'))
  .then((v) => {
    console.log('in two seconds:', v) // in two seconds: Hello
    return 'World'
  })
  .then((v) => {
    console.log(v) // World
    return timethen(2000, v)
  })
  .then((v) => {
    console.log('in two seconds:', v) // in two seconds: World
  })

Package Sidebar

Install

npm i timethen

Weekly Downloads

0

Version

1.0.0

License

MIT

Unpacked Size

3.29 kB

Total Files

6

Last publish

Collaborators

  • nk12