# promise-tracking

> Tracking promise status at multi time-points, and cancel the process if you want.

Latest version **1.0.0** (published 2018-12-25) · ISC license · 0 weekly downloads

## Install

```sh
npm install promise-tracking
pnpm add promise-tracking
yarn add promise-tracking
bun add promise-tracking
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2018-12-25 |
| First published | 2018-12-25 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 11.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Trần Đình Hoàng |
| Maintainers | dinh_hoang |
| Keywords | promise, tracking, at |

## Links

- npm: https://www.npmjs.com/package/promise-tracking
- Repository: https://github.com/hoangtd97/promise-tracking
- Homepage: https://github.com/hoangtd97/promise-tracking#readme
- Issues: https://github.com/hoangtd97/promise-tracking/issues
- npm.io page: https://npm.io/package/promise-tracking

## Alternatives

- [base64url](https://npm.io/package/base64url.md) — 6.1M weekly downloads
- [get-installed-path](https://npm.io/package/get-installed-path.md) — 502.9K weekly downloads
- [@uppy/url](https://npm.io/package/@uppy/url.md) — 185.8K weekly downloads
- [@d3fc/d3fc-shape](https://npm.io/package/@d3fc/d3fc-shape.md) — 16.2K weekly downloads
- [localizer](https://npm.io/package/localizer.md) — 226 weekly downloads

## Recent versions

- 1.0.0 (latest) — 2018-12-25

## README

# Promise Tracking
Tracking promise status at multi time-points, and cancel the process if you want.

## Usage
```js
const PromiseTracking = require('promise-tracking');
const VeryLongTask    = PromiseTracking.timeout(() => 'BIG ENTITY', 5000);

console.time('At');

PromiseTracking(VeryLongTask)
  .at(0, (cancel) => {
    console.timeLog('At', `
    Send request.
    Show loader.`
  )})
  .at(500, (cancel) => console.timeLog('At', `
    This task may take a long time.
    Hide loader.
    Show progress bar.`
  ))
  .at(2000, (cancel) => {
    console.timeLog('At', `
    Server is busy.
    Cancel process.
    Hide progress bar.
    Ask the user to try again later.`);
    cancel();
  })
  .then(val => console.timeLog('At', `
    Create ${val} successfully`
  ))
  .catch(err => console.timeLog('At', `
    ERROR : ${err.message}`
  ));
```

### Will print :
```
At: 2.222ms
    Send request.
    Show loader.
At: 501.650ms
    This task may take a long time.
    Hide loader.
    Show progress bar.
At: 2001.007ms
    Server is busy.
    Cancel process.
    Hide progress bar.
    Ask the user to try again later.
```

### See [example](example.js) for more case.

---

### Injecting at() to Promise class for convenience use :
```js
const PromiseTracking = require('promise-tracking');

PromiseTracking.inject(Promise);

Promise.resolve()
  .at(200, (cancel) => {})
  .then()
```

---
_Source: https://npm.io/package/promise-tracking · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
