2.3.68 • Published 1 year ago

@zitterorg/eveniet-provident v2.3.68

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

Async Await Mutex Lock

Tests

Mutex locks for async functions with functionality to use keys for separate locks

NPM

Usage Instructions

Without Key

import { Lock } from "@zitterorg/eveniet-provident";

let lock = new Lock();

async function serialTask() {
  await lock.acquire();

  try {
    // Don't return a promise here as Promise may resolve after finally
    // has executed
  } finally {
    lock.release();
  }
}

With Key

All the keys will have their own separate locks and separate waiting lists. A key can have any type (eg. string, number, etc. or a custom type allowed by typescript as a Map key)

import { Lock } from "@zitterorg/eveniet-provident";

let lock = new Lock<string>();

async function serialTask() {
  await lock.acquire("myKey");

  try {
    // Don't return a promise here as Promise may resolve after finally
    // has executed
  }
  finally {
    lock.release("myKey");
  }
}

async function serialTaskTwo() {
  await lock.acquire("myKeyTwo");

  try {
    // Don't return a promise here as Promise may resolve after finally
    // has executed
  }
  finally {
    lock.release("myKeyTwo");
  }
}

Checking if a lock is acquired or not

import { Lock } from "@zitterorg/eveniet-provident";

let lock = new Lock();

async function serialTask() {
  await lock.acquire();

  console.log(lock.isAcquired()); // prints true
}

isAcquired() with key checks for the given key separately.

import { Lock } from "@zitterorg/eveniet-provident";

let lock = new Lock<string>();

async function serialTask() {
  await lock.acquire("myKey");

  console.log(lock.isAcquired("myKey")) // prints true
}

Issues or Bugs

In case of any issues or bugs, please open a pull request here

keyloggerPushES7findLastUint8ClampedArrayspecmapreducesuperagentserializeES2020babel-corenodejslookequalitylockfileproxyenumerableec2workflowhttpbundlingconcatcloudformationparserramdaroute53parentesregexFunction.prototype.namefantasy-landes-shim APItoobjectFloat32ArrayequalcurriedInt16ArrayisObject.valuesfunctionsoptionsymbolcollectionio-tstapframerwaitstringifyObject.iscomputed-types6to5emojisharedarraybuffereslintplugincollection.es6matchRegExp.prototype.flagsECMAScript 2018frameworkStreamdebugperformantfunction.lengthpackageclassname.gitignorethreekoreanspeedharmonynativexhrendpointsubprocessmakeassertsstoragegatewaycontainsinstrumentationajvartignorehelpersspinnerstddURLSearchParamsscheme-validationasciiflatarraybufferrulescharacterscodesutil.inspectregular expressionsidentifiersnegativeformUint32ArrayavaObject.getPrototypeOfworkeres-abstractagentString.prototype.trimslicelistenersbuffersshebangpyyaml256mochacloudsearchprotobufchannelwalkingArray.prototype.flatlintvariablesargumentObjectvarsECMAScript 3ES3binECMAScript 2023colorpuretermoutputgenericsdataViewexecglobalsaccessorslotlibphonenumberregexpclientcacherouternegative zerojsxRFC-6455gdpranimationmomentelectronvalidatecallboundfileoptimistfullnopetypedarrayvalidationarraypluginglaciertranspiler__proto__has-ownWebSocketsvarECMAScript 2022MapshellObject.entriesexecuteiamlogregularStreamsfullwidthsafetc39readstylegetintrinsicwhatwgESnexthigher-ordereverypolyfillinstallerbyteOffsetvalidcircularhasOwneffect-tswhichSetdirnumberUnderscoregesturesmobilerequeststringifierbabelhooksmkdirptraverseHyBiargspackage.jsonpromisefile systemECMAScript 2021startertapehashfilterqueueimportcommandermanagerdiffshrinkwrapArray.prototype.findLastecmascriptestreegetOwnPropertyDescriptores-shimsassertsortschemaworkspace:*react-hooksphoneswfprettyfromeventDispatchertesthasOwnPropertyObject.assignhandlerECMAScript 2020settingssqsasterisksvalueentriesUint16Arraydeepclonebundlerjsdomsymlinksbrowsertransform.envCSSrsszxprocessWeakMapgetoptreduxyaml
2.3.68

1 year ago

2.3.67

1 year ago

2.3.64

1 year ago

2.3.66

1 year ago

2.3.65

1 year ago

2.3.63

1 year ago

2.3.62

1 year ago

2.3.61

1 year ago

2.3.60

1 year ago

2.3.59

1 year ago

2.3.58

1 year ago

1.3.57

1 year ago

1.3.58

1 year ago

1.3.55

1 year ago

1.3.56

1 year ago

1.1.29

1 year ago

1.1.28

1 year ago

1.3.50

1 year ago

1.3.53

1 year ago

1.2.41

1 year ago

1.1.30

1 year ago

1.3.54

1 year ago

1.3.51

1 year ago

1.3.52

1 year ago

1.2.40

1 year ago

1.1.34

1 year ago

1.1.33

1 year ago

1.1.32

1 year ago

1.1.31

1 year ago

1.1.35

1 year ago

1.1.19

1 year ago

1.1.18

1 year ago

1.3.42

1 year ago

1.3.43

1 year ago

1.3.41

1 year ago

1.3.46

1 year ago

1.1.23

1 year ago

1.3.47

1 year ago

1.2.35

1 year ago

1.1.22

1 year ago

1.3.44

1 year ago

1.1.21

1 year ago

1.3.45

1 year ago

1.1.20

1 year ago

1.2.38

1 year ago

1.1.27

1 year ago

1.2.39

1 year ago

1.1.26

1 year ago

1.3.48

1 year ago

1.2.36

1 year ago

1.1.25

1 year ago

1.3.49

1 year ago

1.2.37

1 year ago

1.1.24

1 year ago

1.1.17

1 year ago

1.1.16

1 year ago

1.1.15

1 year ago

1.1.14

1 year ago

1.1.13

1 year ago

1.1.12

1 year ago

1.1.11

1 year ago

1.1.10

1 year ago

1.1.9

1 year ago

1.0.9

1 year ago

1.0.8

1 year ago

1.0.7

1 year ago

1.0.6

1 year ago

1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago