# request-last

> request-last

Latest version **0.0.7** (published 2020-03-21) · MIT license · 0 weekly downloads

## Install

```sh
npm install request-last
pnpm add request-last
yarn add request-last
bun add request-last
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.7 |
| Published | 2020-03-21 |
| First published | 2020-03-21 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=7.6 |
| Dependencies | 1 |
| Unpacked size | 7.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | hubiqing |
| Maintainers | g120hbq |
| Keywords | typescript, module-polierplate, request-last |

## Links

- npm: https://www.npmjs.com/package/request-last
- Repository: https://github.com/githbq/hbq-request-last
- Homepage: https://github.com/githbq/hbq-request-last#readme
- Issues: https://github.com/githbq/hbq-request-last/issues
- npm.io page: https://npm.io/package/request-last

## Dependencies (1)

- [tslib](https://npm.io/package/tslib.md) ^1.9.3

## Alternatives

- [@openai/codex-sdk](https://npm.io/package/@openai/codex-sdk.md) — 731.4K weekly downloads
- [babel-plugin-transform-react-jsx](https://npm.io/package/babel-plugin-transform-react-jsx.md) — 565.0K weekly downloads
- [babel-helper-remove-or-void](https://npm.io/package/babel-helper-remove-or-void.md) — 508.5K weekly downloads
- [@pnpm/store-controller-types](https://npm.io/package/@pnpm/store-controller-types.md) — 186.9K weekly downloads
- [react-native-signature-canvas](https://npm.io/package/react-native-signature-canvas.md) — 155.6K weekly downloads

## Recent versions

- 0.0.7 (latest) — 2020-03-21
- 0.0.6 — 2020-03-21
- 0.0.5 — 2020-03-21
- 0.0.4 — 2020-03-21
- 0.0.3 — 2020-03-21
- 0.0.2 — 2020-03-21
- 0.0.1 — 2020-03-21

## README

> 对异步函数，多次执行始终返回最后一次执行的结果，
解决慢执行结果覆盖最后一次执行结果的问题
 
## 安装
```
npm i request-last
```

## 使用  

```js
import requestLast from 'reqeust-last'   
{
  reqeust:requestLast(function (){
    return yourAsyncFunciton(/*...*/) 
  })
}
```

## 代码

```js
export default function requestLast(fn) {
  let totalTimes = 0
  return function requestLastHandleFn(...args) {
    const times = ++totalTimes
    return new Promise((resolve, reject) => {
      fn.apply(this, args).then(result => {
        if (times === totalTimes) {
          resolve(result)
        }
      }, (e) => {
        if (times === totalTimes) {
          reject(e)
        }
      })
    })
  }
} 
```

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