# last-one-wins

> Make sure the last sync call to an async function is executed after all previous ones have finished

Latest version **1.0.4** (published 2016-01-30) · MIT license · 0 weekly downloads

## Install

```sh
npm install last-one-wins
pnpm add last-one-wins
yarn add last-one-wins
bun add last-one-wins
```

## 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.4 |
| Published | 2016-01-30 |
| First published | 2015-11-28 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 31 |
| Author | Mathias Buus |
| Maintainers | mafintosh |

## Links

- npm: https://www.npmjs.com/package/last-one-wins
- Repository: https://github.com/mafintosh/last-one-wins
- Issues: https://github.com/mafintosh/last-one-wins/issues
- npm.io page: https://npm.io/package/last-one-wins

## Recent versions

- 1.0.4 (latest) — 2016-01-30
- 1.0.3 — 2016-01-25
- 1.0.2 — 2016-01-13
- 1.0.1 — 2016-01-13
- 1.0.0 — 2015-11-28

## README

# last-one-wins

Make sure the last sync call to an async function is executed after all previous ones have finished

```
npm install last-one-wins
```

[![build status](http://img.shields.io/travis/mafintosh/last-one-wins.svg?style=flat)](http://travis-ci.org/mafintosh/last-one-wins)

## Usage

``` js
var low = require('last-one-wins')

var pick = low(function (num, cb) {
  setTimeout(function () {
    console.log('picked', num)
    cb()
  }, Math.floor(Math.random() * 100))
})

pick(1)
pick(2)
pick(3)
pick(4)
pick(5) // this one will always win since its called the last
```

Calling the above will print out

```
picked 1
picked 5
```

## API

#### `var fn = low(asyncWorker)`

Wrap a async function to make sure that the last sync call to that
function is executed after any previous calls. Note that not all calls
are executed - only the last one is guaranteed to be executed.

`fn` and `asyncWorker` should have the signature `(value, cb)`

## Use with leveldb

This module is useful if you want sync a value to a leveldb and want to
make sure the latest version of that value is the one written. For example

``` js
var update = low(function (val, cb) {
  db.put('my-key', val, cb)
})

update('a')
update('b')
update('c')
```

Is guaranteed to always write `c` to the key `my-key`.

## License

MIT

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