Nanobots Producing Megastructures

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

    1.0.1 • Public • Published

    abortable-timeout

    abortable timeout promise via abortsignals

    Installation

    npm i --save abortable-timeout

    Usage

    Supports both ESM and CommonJS

    // esm
    import timeout from 'abortable-timeout`
    // commonjs
    const timeout = require('abortable-timeout').default

    Example

    import timeout from 'abortable-timeout`
    
    const controller = new AbortController()
    const signal = controller.signal
    
    try {
      await timeout(1000, signal)
    } catch(err) {
      if (err.name === 'AbortError') {
        console.warn('aborted')
        return
      }
      throw err
    }
    
    controller.abort()

    License

    MIT

    Install

    npm i abortable-timeout

    DownloadsWeekly Downloads

    2

    Version

    1.0.1

    License

    MIT

    Unpacked Size

    16.5 kB

    Total Files

    16

    Last publish

    Collaborators

    • tjmehta