@mainframe/utils-time
Time-related utilities
Last updated 2 years ago by paul_lecam .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install @mainframe/utils-time 
SYNC missed versions from official npm registry.

utils-time

Time-related utilities.

Installation

yarn add @mainframe/utils-time

Usage

import { createWithTimeout, TimeoutError, withTimeout } from 'utils-id'

const max10secs = createWithTimeout(10000)

const run = async () => {
  try {
    const tooLong = await max10secs(fetch(...))
  } catch (err) {
    if (err instanceof TimeoutError) {
      ...
    }
  }

  const longerTime = await withTimeout(fetch(...), 60 * 1000) // 1 min
}

API

sleep

Waits for the given time before resolving.

Arguments

  1. time: number

Returns Promise<void>

new TimeoutError

Arguments

  1. message: string

withTimeout

Races between the given wait promise and time before rejecting with a TimeoutError.

Arguments

  1. wait: Promise<T>
  2. time: number

Returns Promise<T>

createWithTimeout

Creates a withTimeout() function with a given default time.

Arguments

  1. time: number

Returns (wait: Promise<T>, time?: number) => Promise<T>

createGetTime

Creates function that will return an always increasing current time value based on Date.now().

Returns () => number

License

MIT

Current Tags

  • 0.2.0                                ...           latest (2 years ago)

2 Versions

  • 0.2.0                                ...           2 years ago
  • 0.1.0                                ...           2 years ago
Downloads
Today 0
This Week 0
This Month 1
Last Day 0
Last Week 0
Last Month 0
Dependencies (1)
Dev Dependencies (0)
None
Dependents (0)
None

Copyright 2014 - 2017 © taobao.org |