p-after

Resolve a promise after an amount of time with specified data

Usage no npm install needed!

<script type="module">
  import pAfter from 'https://cdn.skypack.dev/p-after';
</script>

README

p-after

Build Status JavaScript Style Guide

Resolve a promise with specified data after an amount of time

Useful if you want to return data after some time, for example, if you want to sequence data at varying rates.

Usage

const after = require('p-after')
(async () => {
  const result = await after(1000, 'OK')
  // After one second, the promise resolves with 'OK'. 
})

API

pAfter(when, what)

when

Type: number

The amount of time to delay returning the data.

what

Type: any

The data to return after delay.

Related

  • delay - Delay a promise a specified amount of time
  • p-min-delay - Delay an existing promise a minimum amount of time
  • p-immediate - Returns a promise resolved in the next event loop - think setImmediate()
  • p-timeout - Timeout a promise after a specified amount of time
  • Moreā€¦