# jackall

> async/await for optimistic concurrency control.(Last in wins.)

Latest version **1.2.1** (published 2020-10-24) · MIT license · 0 weekly downloads

## Install

```sh
npm install jackall
pnpm add jackall
yarn add jackall
bun add jackall
```

## 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.2.1 |
| Published | 2020-10-24 |
| First published | 2020-10-23 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 15.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | hikouki |
| Maintainers | hikouki |
| Keywords | typescript, async, await, promise, optimistic, concurrency, last in wins |

## Links

- npm: https://www.npmjs.com/package/jackall
- Repository: https://github.com/hikouki/jackall
- Homepage: https://github.com/hikouki/jackall#readme
- Issues: https://github.com/hikouki/jackall/issues
- npm.io page: https://npm.io/package/jackall

## Alternatives

- [@commercetools/sync-actions](https://npm.io/package/@commercetools/sync-actions.md) — 25.1K weekly downloads
- [cwait](https://npm.io/package/cwait.md) — 21.4K weekly downloads
- [@ledgerhq/hw-app-cosmos](https://npm.io/package/@ledgerhq/hw-app-cosmos.md) — 4.2K weekly downloads
- [@financial-times/o-loading](https://npm.io/package/@financial-times/o-loading.md) — 2.8K weekly downloads
- [fa](https://npm.io/package/fa.md) — 185 weekly downloads

## Recent versions

- 1.2.1 (latest) — 2020-10-24
- 1.2.0 — 2020-10-23
- 1.1.0 — 2020-10-23
- 1.0.0 — 2020-10-23

## README

# Jackall

async/await for optimistic concurrency control. (Last in wins.)

## Install

```
npm install jackall
```

## Usage

Please refer to [tests](https://github.com/hikouki/jackall/blob/main/__tests__/index.spec.ts).

```typescript
import { jackall } from "jackall";

// async tasks.
const task1 = async () => new Promise((ok) => setTimeout(ok, 100, "ping1"));
const task2 = async () => new Promise((ok) => setTimeout(ok, 200, "ping2"));

// jackall.acquire. (resource name is `tiger`)
const [act1, act2] = await Promise.all([
  jackall.acquire("tiger", task1()),
  jackall.acquire("tiger", task2()),
]);

// last in wins.
// act1 => { ok: false, code: JACKALL_ERROR_CODE.NOMATCH_VERSION, value: new Error(`Jackall Error: ${JACKALL_ERROR_CODE.NOMATCH_VERSION}`) }
// act2 => { ok: true, value: "ping2" }
```

If you want to specify a resource name.

```typescript
import { makeJackall } from "jackall";

const jackall = makeJackall<"tiger">();

// jackall.acquire("tiger", task1()) => OK
// jackall.acquire("bear", task1()) => NG
```

## Error Codes

```typescript
import { JACKALL_ERROR_CODE } from "jackall";
```

| option             | description                                 |
|--------------------|---------------------------------------------|
| FAILED_ASYNCTASK   | Failed to Async task.                       |
| NOMATCH_VERSION    | Lost in the race conditions.(Last in Wins.) |

## License

Jackall is [MIT licensed](https://github.com/hikouki/jackall/blob/main/LICENSE).

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