with-timeout

Promisified, boilerplate-free setTimeout

Usage no npm install needed!

<script type="module">
  import withTimeout from 'https://cdn.skypack.dev/with-timeout';
</script>

README

with-timeout

Promisified, boilerplate-free setTimeout

Build Status Coverage Status npm version JavaScript Style Guide

Install

$ npm install --save with-timeout

Not using Node or a module bundler? Use a UMD build via the <script> tag.

Usage

import withTimeout from 'with-timeout'

const fn = (firstName = 'Agent', lastName = 'Smith') =>
  `Hello ${firstName} ${lastName}`

// After 500ms - 'Hello Agent Smith'
withTimeout(fn).then(console.log)

// After 1000ms - 'Hello Keanu Reeves'
withTimeout(fn, 1000, 'Keanu', 'Reeves').then(console.log)