Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sindresorhus/p-time
Measure the time a promise takes to resolve
https://github.com/sindresorhus/p-time
Last synced: about 1 month ago
JSON representation
Measure the time a promise takes to resolve
- Host: GitHub
- URL: https://github.com/sindresorhus/p-time
- Owner: sindresorhus
- License: mit
- Created: 2016-07-11T23:45:42.000Z (over 8 years ago)
- Default Branch: main
- Last Pushed: 2023-11-05T20:54:35.000Z (about 1 year ago)
- Last Synced: 2024-04-13T17:54:21.543Z (7 months ago)
- Language: JavaScript
- Homepage:
- Size: 15.6 KB
- Stars: 68
- Watchers: 6
- Forks: 5
- Open Issues: 1
-
Metadata Files:
- Readme: readme.md
- License: license
Awesome Lists containing this project
- promise-fun - p-time
README
# p-time
> Measure the time a promise takes to resolve
## Install
```sh
npm install p-time
```## Usage
```js
import pTime from 'p-time';
import {execa} from 'execa';const promise = pTime(execa)('sleep', ['1']);
await promise;
console.log(promise.time);
//=> 1016
```## API
### pTime(asyncFunction)
Returns a decorated version of `asyncFunction` that when called returns a `Promise` with a `time` property of the elapsed time in milliseconds.
### pTime.log(asyncFunction)
Returns a decorated version of `asyncFunction` that when called logs the elapsed time in milliseconds of the `Promise`.
#### asyncFunction
Type: `Function`
Promise-returning/async function.
## Related
- [p-log](https://github.com/sindresorhus/p-log) - Log the value/error of a promise
- [More…](https://github.com/sindresorhus/promise-fun)