Skip to content

Commit

Permalink
Merge PR #2 from 'nodech/ts-lint'
Browse files Browse the repository at this point in the history
  • Loading branch information
nodech committed Aug 31, 2023
2 parents 49ca1de + 64c3689 commit 001119f
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 10 deletions.
15 changes: 11 additions & 4 deletions lib/lock.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ const assert = require('bsert');
*/

class Lock {
/** @type {Boolean} */
named;

/** @type {Map} */
map;

/**
* Create a lock.
* @constructor
Expand All @@ -30,6 +36,7 @@ class Lock {
this.busy = false;
this.destroyed = false;

// @ts-ignore
this.map = CustomMap ? new CustomMap() : new Map();
this.current = null;

Expand Down Expand Up @@ -94,9 +101,9 @@ class Lock {
/**
* Lock the parent object and all its methods
* which use the lock. Begin to queue calls.
* @param {String?} name - Job name.
* @param {Boolean?} force - Bypass the lock.
* @returns {Promise} - Returns {Function}, must be
* @param {String|Boolean} [arg1] - Job name or bypass the lock.
* @param {Boolean} [arg2=false] - Bypass the lock.
* @returns {Promise<Function>} - Returns {Function}, must be
* called once the method finishes executing in order
* to resolve the queue.
*/
Expand Down Expand Up @@ -201,7 +208,7 @@ class Job {
* @constructor
* @param {Function} resolve
* @param {Function} reject
* @param {String?} name
* @param {String} [name]
*/

constructor(resolve, reject, name) {
Expand Down
14 changes: 12 additions & 2 deletions lib/maplock.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ const assert = require('bsert');
*/

class MapLock {
/** @type {Map} */
jobs;

/** @type {Set} */
busy;

/**
* Create a mapped lock.
* @param {Function?} CustomMap
Expand All @@ -27,7 +33,9 @@ class MapLock {
this.Map = CustomMap || Map;
this.Set = CustomSet || Set;

// @ts-ignore
this.jobs = new this.Map();
// @ts-ignore
this.busy = new this.Set();

this.destroyed = false;
Expand Down Expand Up @@ -75,7 +83,7 @@ class MapLock {
* Begin to queue calls.
* @param {String|Number} key
* @param {Boolean} [force=false] - Force a call.
* @returns {Promise} - Returns {Function}, must be
* @returns {Promise<Function>} - Returns {Function}, must be
* called once the method finishes executing in order
* to resolve the queue.
*/
Expand Down Expand Up @@ -108,7 +116,7 @@ class MapLock {
/**
* Create an unlock callback.
* @private
* @param {String} key
* @param {String|Number} key
* @returns {Function} Unlocker.
*/

Expand Down Expand Up @@ -159,7 +167,9 @@ class MapLock {

this.destroyed = true;

// @ts-ignore
this.jobs = new this.Map();
// @ts-ignore
this.busy = new this.Set();

for (const jobs of map.values()) {
Expand Down
11 changes: 9 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@
"main": "./lib/bmutex.js",
"scripts": {
"lint": "eslint lib/ test/",
"lint-types": "tsc -p .",
"test": "bmocha --reporter spec test/*-test.js"
},
"dependencies": {
"bsert": "~0.0.10"
"bsert": "~0.0.12"
},
"devDependencies": {
"bmocha": "^2.1.0"
"bmocha": "^2.1.8",
"bts-type-deps": "^0.0.3"
},
"engines": {
"node": ">=8.0.0"
Expand Down
31 changes: 31 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"include": [
"lib/**/*.js"
],
"compilerOptions": {
"rootDir": ".",
"target": "ES2020",
"lib": [
"ES2020"
],

"noEmit": true,

"allowJs": true,
"checkJs": true,
"maxNodeModuleJsDepth": 10,

"module": "commonjs",
"moduleResolution": "node",
"resolveJsonModule": true,

"stripInternal": true,
"noImplicitThis": true,
"noUnusedLocals": true,
"noUnusedParameters": false,

"typeRoots": [
"node_modules/bts-type-deps/types"
]
}
}

0 comments on commit 001119f

Please sign in to comment.