git ssb

0+

wanderer🌟 / lockmap



Commit e266f356cf9c371ca1664d82d1192822aa48fbef

uses all map props

Signed-off-by: wanderer <mjbecze@gmail.com>
wanderer committed on 11/17/2017, 10:35:37 PM
Parent: d875b8b05b237bdbe18027c2d27eb7ff8197110e

Files changed

index.jschanged
package.jsonchanged
tests/index.jschanged
index.jsView
@@ -3,8 +3,16 @@
33 * Creates a new instance of LockMap
44 */
55 constructor () {
66 this._map = new Map()
7 +
8 + const methods = ['clear', 'delete', 'entries', 'forEach', 'get', 'has', 'keys', 'values', Symbol.iterator]
9 + const self = this
10 + methods.forEach(method => {
11 + self[method] = function () {
12 + return self._map[method].apply(self._map, arguments)
13 + }
14 + })
715 }
816
917 /**
1018 * Creates a lock on a given ID and returns a resolve function to unlock the
@@ -23,13 +31,12 @@
2331 this._map.set(id, promise)
2432 return r
2533 }
2634
27- /**
28- * gets the current lock if any for a given id. If there is a lock this will
29- * return a promise that resolves once the lock is unlocked
30- * @return {Promise}
31- */
32- getLock (id) {
33- return this._map.get(id)
35 + get size () {
36 + return this._map.size
3437 }
38 +
39 + get [Symbol.toStringTag] () {
40 + return 'LockMap'
41 + }
3542 }
package.jsonView
@@ -3,10 +3,10 @@
33 "version": "0.0.0",
44 "description": "Creates a promise based map of locks that can be used as a semaphore",
55 "main": "index.js",
66 "scripts": {
7- "coverage": "istanbul cover ./tests/index.js",
8- "coveralls": "npm run coverage && coveralls <coverage/lcov.info",
7 + "coverage": "nyc npm test",
8 + "coveralls": "npm run coverage && nyc report --reporter=text-lcov | coveralls",
99 "lint": "standard",
1010 "test": "node ./tests/index.js",
1111 "build:docs": "documentation build --github -f md ./index.js > ./docs/index.md"
1212 },
@@ -14,14 +14,13 @@
1414 ""
1515 ],
1616 "author": "mjbecze <mjbecze@gmail.com>",
1717 "license": "MPL-2.0",
18- "dependencies": {
19- },
18 + "dependencies": {},
2019 "devDependencies": {
20 + "documentation": "^5.3.3",
2121 "coveralls": "^3.0.0",
22- "documentation": "^5.2.0",
23- "istanbul": "^0.4.1",
22 + "nyc": "^11.3.0",
2423 "standard": "^10.0.0",
2524 "tape": "^4.0.3"
2625 },
2726 "repository": {
tests/index.jsView
@@ -1,11 +1,12 @@
11 const tape = require('tape')
22 const LockMap = require('../')
33
44 tape('lockmap tests', async t => {
5- t.plan(2)
5 + t.plan(4)
66 // create a new lock map
77 const lockmap = new LockMap()
8 + t.equals(lockmap.toString(), '[object LockMap]')
89 const id = 'test'
910
1011 let first = true
1112
@@ -18,8 +19,10 @@
1819 first = false
1920 unlock()
2021 }, 300)
2122
23 + t.equals(lockmap.size, 1)
24 +
2225 // wait until the lock resolves
23- await lockmap.getLock(id)
26 + await lockmap.get(id)
2427 t.equals(first, false)
2528 })

Built with git-ssb-web