jackall

1.2.1 • Public • Published

Jackall

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

Install

npm install jackall

Usage

Please refer to tests.

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.

import { makeJackall } from "jackall";
 
const jackall = makeJackall<"tiger">();
 
// jackall.acquire("tiger", task1()) => OK
// jackall.acquire("bear", task1()) => NG

Error Codes

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.

Package Sidebar

Install

npm i jackall

Weekly Downloads

2

Version

1.2.1

License

MIT

Unpacked Size

15.5 kB

Total Files

8

Last publish

Collaborators

  • hikouki