Skip to content

wareset/timethen

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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
  })

About

Awaiting timeout. Very small function

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published