appium-mac2-driver 4.3.6 → 4.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/WebDriverAgentMac/IntegrationTests/AMSessionTests.m +14 -0
- package/WebDriverAgentMac/WebDriverAgentLib/Commands/FBSessionCommands.m +17 -5
- package/WebDriverAgentMac/WebDriverAgentLib/Routing/FBSession.m +5 -1
- package/build/lib/driver.d.ts +3 -0
- package/build/lib/driver.d.ts.map +1 -1
- package/build/lib/driver.js +52 -32
- package/build/lib/driver.js.map +1 -1
- package/build/lib/session-claim-handler.d.ts +41 -0
- package/build/lib/session-claim-handler.d.ts.map +1 -0
- package/build/lib/session-claim-handler.js +236 -0
- package/build/lib/session-claim-handler.js.map +1 -0
- package/build/lib/wda-mac.d.ts +6 -2
- package/build/lib/wda-mac.d.ts.map +1 -1
- package/build/lib/wda-mac.js +39 -9
- package/build/lib/wda-mac.js.map +1 -1
- package/lib/driver.ts +55 -31
- package/lib/session-claim-handler.ts +306 -0
- package/lib/wda-mac.ts +41 -10
- package/node_modules/appium-xcode/CHANGELOG.md +7 -0
- package/node_modules/appium-xcode/package.json +4 -4
- package/node_modules/async-lock/AUTHORS +21 -0
- package/node_modules/async-lock/History.md +132 -0
- package/node_modules/async-lock/LICENSE +22 -0
- package/node_modules/async-lock/README.md +177 -0
- package/node_modules/async-lock/index.js +2 -0
- package/node_modules/async-lock/lib/index.js +312 -0
- package/node_modules/async-lock/package.json +48 -0
- package/node_modules/bare-fs/binding.c +1 -1
- package/node_modules/bare-fs/index.js +30 -6
- package/node_modules/bare-fs/package.json +1 -1
- package/node_modules/bare-fs/prebuilds/android-arm/bare-fs.bare +0 -0
- package/node_modules/bare-fs/prebuilds/android-arm64/bare-fs.bare +0 -0
- package/node_modules/bare-fs/prebuilds/android-ia32/bare-fs.bare +0 -0
- package/node_modules/bare-fs/prebuilds/android-x64/bare-fs.bare +0 -0
- package/node_modules/bare-fs/prebuilds/darwin-arm64/bare-fs.bare +0 -0
- package/node_modules/bare-fs/prebuilds/darwin-x64/bare-fs.bare +0 -0
- package/node_modules/bare-fs/prebuilds/ios-arm64/bare-fs.bare +0 -0
- package/node_modules/bare-fs/prebuilds/ios-arm64-simulator/bare-fs.bare +0 -0
- package/node_modules/bare-fs/prebuilds/ios-x64-simulator/bare-fs.bare +0 -0
- package/node_modules/bare-fs/prebuilds/linux-arm64/bare-fs.bare +0 -0
- package/node_modules/bare-fs/prebuilds/linux-x64/bare-fs.bare +0 -0
- package/node_modules/bare-fs/prebuilds/win32-arm64/bare-fs.bare +0 -0
- package/node_modules/bare-fs/prebuilds/win32-x64/bare-fs.bare +0 -0
- package/node_modules/readable-stream/lib/internal/shims/process.js +19 -0
- package/node_modules/readable-stream/lib/internal/streams/destroy.js +1 -1
- package/node_modules/readable-stream/lib/internal/streams/duplexify.js +1 -1
- package/node_modules/readable-stream/lib/internal/streams/end-of-stream.js +1 -1
- package/node_modules/readable-stream/lib/internal/streams/from.js +1 -1
- package/node_modules/readable-stream/lib/internal/streams/legacy.js +6 -1
- package/node_modules/readable-stream/lib/internal/streams/pipeline.js +1 -1
- package/node_modules/readable-stream/lib/internal/streams/readable.js +1 -1
- package/node_modules/readable-stream/lib/internal/streams/writable.js +1 -1
- package/node_modules/readable-stream/package.json +3 -2
- package/node_modules/tar-stream/package.json +7 -7
- package/package.json +4 -2
package/lib/wda-mac.ts
CHANGED
|
@@ -301,7 +301,8 @@ export class WDAMacServer {
|
|
|
301
301
|
return this._proxy;
|
|
302
302
|
}
|
|
303
303
|
|
|
304
|
-
|
|
304
|
+
/** Starts a WDA session, replacing the previous one. Returns the new WDA session id. */
|
|
305
|
+
async startSession(caps: StartSessionCapabilities, opts: SessionOptions = {}): Promise<string> {
|
|
305
306
|
this._serverStartupTimeoutMs = caps.serverStartupTimeout ?? this._serverStartupTimeoutMs;
|
|
306
307
|
|
|
307
308
|
this._isProxyingToRemoteServer = !!caps.webDriverAgentMacUrl;
|
|
@@ -381,23 +382,53 @@ export class WDAMacServer {
|
|
|
381
382
|
log.info('The host process has already been listening. Proceeding with session creation');
|
|
382
383
|
}
|
|
383
384
|
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
385
|
+
// WDA drops the previous session as soon as it gets this request,
|
|
386
|
+
// so a failure must not leave the proxy pointing at the replaced one
|
|
387
|
+
try {
|
|
388
|
+
await this._proxy.command('/session', 'POST', {
|
|
389
|
+
capabilities: {
|
|
390
|
+
firstMatch: [{}],
|
|
391
|
+
alwaysMatch: caps,
|
|
392
|
+
},
|
|
393
|
+
});
|
|
394
|
+
} catch (e) {
|
|
395
|
+
this._proxy.sessionId = null;
|
|
396
|
+
throw e;
|
|
397
|
+
}
|
|
398
|
+
const sessionId = this._proxy.sessionId;
|
|
399
|
+
if (!sessionId) {
|
|
400
|
+
throw new errors.SessionNotCreatedError('WebDriverAgentMac did not return a session id');
|
|
401
|
+
}
|
|
402
|
+
return sessionId;
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
/** Whether the WDA session has not been replaced by a newer one. */
|
|
406
|
+
isSessionActive(sessionId: string | null | undefined): boolean {
|
|
407
|
+
return !!sessionId && this._proxy?.sessionId === sessionId;
|
|
390
408
|
}
|
|
391
409
|
|
|
392
|
-
|
|
410
|
+
/** Stops the WDA session. A replaced one is skipped, so the newer one is never affected. */
|
|
411
|
+
async stopSession(sessionId: string | null | undefined): Promise<void> {
|
|
393
412
|
if (!this._isProxyingToRemoteServer && !this._process?.isRunning) {
|
|
394
413
|
log.info(`Mac2Driver session cannot be stopped, because the server is not running`);
|
|
395
414
|
return;
|
|
396
415
|
}
|
|
397
416
|
|
|
398
|
-
if (this.
|
|
417
|
+
if (!this.isSessionActive(sessionId)) {
|
|
418
|
+
if (sessionId) {
|
|
419
|
+
log.info(`Mac2Driver session '${sessionId}' is not active anymore. Nothing to stop`);
|
|
420
|
+
}
|
|
421
|
+
return;
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
const proxy = this._proxy;
|
|
425
|
+
if (proxy) {
|
|
399
426
|
try {
|
|
400
|
-
await
|
|
427
|
+
await proxy.command(`/session/${sessionId}`, 'DELETE');
|
|
428
|
+
// A newer session might have been created while the DELETE was pending
|
|
429
|
+
if (proxy.sessionId === sessionId) {
|
|
430
|
+
proxy.sessionId = null;
|
|
431
|
+
}
|
|
401
432
|
} catch (e: any) {
|
|
402
433
|
log.info(`Mac2Driver session cannot be deleted. Original error: ${e.message}`);
|
|
403
434
|
}
|
|
@@ -3,6 +3,13 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [7.2.3](https://github.com/appium/appium-ios/compare/appium-xcode@7.2.2...appium-xcode@7.2.3) (2026-10-02)
|
|
7
|
+
|
|
8
|
+
### Miscellaneous Chores
|
|
9
|
+
|
|
10
|
+
* ensure Dependabot preserves version ranges ([#24](https://github.com/appium/appium-ios/issues/24)) ([95e4e1a](https://github.com/appium/appium-ios/commit/95e4e1a4703f8ca833f01ecf2af75f4696d98043))
|
|
11
|
+
|
|
12
|
+
|
|
6
13
|
## [7.2.2](https://github.com/appium/appium-ios/compare/appium-xcode@7.2.1...appium-xcode@7.2.2) (2026-10-01)
|
|
7
14
|
|
|
8
15
|
**Note:** Version bump only for package appium-xcode
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "appium-xcode",
|
|
3
|
-
"version": "7.2.
|
|
3
|
+
"version": "7.2.3",
|
|
4
4
|
"description": "Interact with Xcode",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"appium",
|
|
@@ -44,18 +44,18 @@
|
|
|
44
44
|
"dependencies": {
|
|
45
45
|
"@appium/support": "^7.2.8",
|
|
46
46
|
"asyncbox": "^6.4.3",
|
|
47
|
-
"semver": "7.8.5",
|
|
47
|
+
"semver": "^7.8.5",
|
|
48
48
|
"teen_process": "^4.2.1"
|
|
49
49
|
},
|
|
50
50
|
"devDependencies": {
|
|
51
51
|
"@appium/tsconfig": "^1.2.1",
|
|
52
52
|
"@appium/types": "^1.7.1",
|
|
53
|
-
"@types/node": "26.6.3",
|
|
53
|
+
"@types/node": "^26.6.3",
|
|
54
54
|
"@types/semver": "^7.8.0"
|
|
55
55
|
},
|
|
56
56
|
"engines": {
|
|
57
57
|
"node": "^20.19.0 || ^22.12.0 || >=24.0.0",
|
|
58
58
|
"npm": ">=10"
|
|
59
59
|
},
|
|
60
|
-
"gitHead": "
|
|
60
|
+
"gitHead": "da9df509454bca268192150e4d3302d7f000a5c9"
|
|
61
61
|
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# Authors ordered by first contribution.
|
|
2
|
+
|
|
3
|
+
rain1017 (https://github.com/rain1017)
|
|
4
|
+
JonathanPicques (https://github.com/JonathanPicques)
|
|
5
|
+
Rogier Schouten (https://github.com/rogierschouten)
|
|
6
|
+
erikvold (https://github.com/erikvold)
|
|
7
|
+
Christian Passet (https://github.com/thePunIssuer)
|
|
8
|
+
Tanguy Krotoff (https://github.com/tkrotoff)
|
|
9
|
+
jtyers (https://github.com/jtyers)
|
|
10
|
+
Paul Roub (https://github.com/paulroub)
|
|
11
|
+
Geoff Whatley (https://github.com/meatwallace)
|
|
12
|
+
Patryk L. (https://github.com/LosTigeros)
|
|
13
|
+
Julian Saunderson (https://github.com/bitrivers)
|
|
14
|
+
Philipp Keck (https://github.com/Philipp91)
|
|
15
|
+
abozaralizadeh (https://github.com/abozaralizadeh)
|
|
16
|
+
ThePiz (https://github.com/ThePiz)
|
|
17
|
+
Luke Stead (https://github.com/luke-stead-sonocent)
|
|
18
|
+
Simeon Borko (https://github.com/simeonborko)
|
|
19
|
+
Tim Schmidt (https://github.com/taschmidt)
|
|
20
|
+
Motty Milshtein (https://github.com/mottymilshtein)
|
|
21
|
+
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
1.4.0
|
|
2
|
+
==================
|
|
3
|
+
* add execution timeout (thank you @mottymilshtein)
|
|
4
|
+
|
|
5
|
+
1.3.2
|
|
6
|
+
==================
|
|
7
|
+
* Handle errors from user-supplied callback better (Thank you @simeonborko)
|
|
8
|
+
* Ensure the array parameter does not get mutated for batch acquire (Thank you @taschmidt)
|
|
9
|
+
|
|
10
|
+
1.3.1
|
|
11
|
+
==================
|
|
12
|
+
* Show queue name in errors (thank you @luke-stead-sonocent)
|
|
13
|
+
|
|
14
|
+
1.3.0
|
|
15
|
+
==================
|
|
16
|
+
* Add maxOccupationTime option (Thank you @abozaralizadeh and @ThePiz)
|
|
17
|
+
|
|
18
|
+
1.2.8
|
|
19
|
+
==================
|
|
20
|
+
* Fix #37 process not set when acquiring lock (Thank you @Philipp91)
|
|
21
|
+
|
|
22
|
+
1.2.7
|
|
23
|
+
==================
|
|
24
|
+
DO NOT USE, erroneous publish
|
|
25
|
+
|
|
26
|
+
1.2.6
|
|
27
|
+
==================
|
|
28
|
+
* Fix `maxPending = Infinity` no longer allowed (thank you @coderaiser)
|
|
29
|
+
|
|
30
|
+
1.2.5
|
|
31
|
+
==================
|
|
32
|
+
* Allow `maxPending = 0` (thank you @bmrpatel)
|
|
33
|
+
* Upgrade dependencies
|
|
34
|
+
|
|
35
|
+
1.2.4
|
|
36
|
+
==================
|
|
37
|
+
* Be robust to lock names that are also Object keys - simpler solution, extra tests.
|
|
38
|
+
|
|
39
|
+
1.2.3
|
|
40
|
+
==================
|
|
41
|
+
* Be robust to lock names that are also Object keys.
|
|
42
|
+
* Upgrade dependencies
|
|
43
|
+
|
|
44
|
+
1.2.2
|
|
45
|
+
==================
|
|
46
|
+
* Fix grunt-env accidentally having become a dependency (#25)
|
|
47
|
+
|
|
48
|
+
1.2.1
|
|
49
|
+
==================
|
|
50
|
+
* Remove empty postinstall script (#24)
|
|
51
|
+
* Fixed some vulnerable dev dependencies
|
|
52
|
+
|
|
53
|
+
1.2.0
|
|
54
|
+
==================
|
|
55
|
+
* ES5 compatibility (#21)
|
|
56
|
+
|
|
57
|
+
1.1.4
|
|
58
|
+
==================
|
|
59
|
+
* Fix for #17, update dependencies
|
|
60
|
+
|
|
61
|
+
1.1.3
|
|
62
|
+
==================
|
|
63
|
+
* Fix for #14
|
|
64
|
+
|
|
65
|
+
1.1.1
|
|
66
|
+
==================
|
|
67
|
+
* Fix result Promise not resolving when locking empty key array
|
|
68
|
+
|
|
69
|
+
1.1.0 / 2017-10-17
|
|
70
|
+
==================
|
|
71
|
+
* Add option to add waiters to the front of the queue
|
|
72
|
+
|
|
73
|
+
1.1.0 / 2017-10-17
|
|
74
|
+
==================
|
|
75
|
+
* Add option to add waiters to the front of the queue
|
|
76
|
+
|
|
77
|
+
1.0.0 / 2017-06-29
|
|
78
|
+
==================
|
|
79
|
+
* Remove dependency on Q by using the global Promise variable by default. Thank you @erikvold (https://github.com/erikvold) for the PR
|
|
80
|
+
|
|
81
|
+
0.3.10 / 2017-06-27
|
|
82
|
+
==================
|
|
83
|
+
* Remove dependencies on Q-specific nodify(), try(), and defer() methods so that you can inject e.g. standard ES6 promises using `new AsyncLock({ Promise: Promise })`
|
|
84
|
+
|
|
85
|
+
0.3.9 / 2016-11-30
|
|
86
|
+
==================
|
|
87
|
+
* Referred to MIT license in package.json
|
|
88
|
+
* Update NPM module dependencies, remove no-longer-maintained blanket code coverage
|
|
89
|
+
* Change author to rogierschouten
|
|
90
|
+
* Fix invalid JSDoc comments (thanks @JonathanPicques)
|
|
91
|
+
* Bugfix: TypeError when locking multiple keys at once
|
|
92
|
+
|
|
93
|
+
0.3.7-0.3.8
|
|
94
|
+
==================
|
|
95
|
+
Unknown, previous author did not commit this to Github.
|
|
96
|
+
|
|
97
|
+
0.3.6 / 2015-09-07
|
|
98
|
+
==================
|
|
99
|
+
* Performance improvement
|
|
100
|
+
|
|
101
|
+
0.3.5 / 2015-06-15
|
|
102
|
+
==================
|
|
103
|
+
* Performance improvement
|
|
104
|
+
|
|
105
|
+
0.3.4 / 2015-06-09
|
|
106
|
+
==================
|
|
107
|
+
* Bug fix
|
|
108
|
+
|
|
109
|
+
0.3.3 / 2015-05-19
|
|
110
|
+
==================
|
|
111
|
+
* Bug fix
|
|
112
|
+
|
|
113
|
+
0.3.2 / 2015-05-08
|
|
114
|
+
==================
|
|
115
|
+
* Set default timeout to never
|
|
116
|
+
|
|
117
|
+
0.3.1 / 2015-04-15
|
|
118
|
+
==================
|
|
119
|
+
* Use your own promise
|
|
120
|
+
|
|
121
|
+
0.3.0 / 2015-03-06
|
|
122
|
+
==================
|
|
123
|
+
* Domain reentrant
|
|
124
|
+
|
|
125
|
+
0.2.0 / 2015-02-21
|
|
126
|
+
==================
|
|
127
|
+
* Support promise mode
|
|
128
|
+
* Pending task limit
|
|
129
|
+
|
|
130
|
+
0.1.0 / 2015-01-13
|
|
131
|
+
==================
|
|
132
|
+
* Initial version
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2016 Rogier Schouten <github@workingcode.ninja>
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
22
|
+
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
# async-lock
|
|
2
|
+
|
|
3
|
+
Lock on asynchronous code
|
|
4
|
+
|
|
5
|
+
[](https://travis-ci.org/rogierschouten/async-lock)
|
|
6
|
+
|
|
7
|
+
* ES6 promise supported
|
|
8
|
+
* Multiple keys lock supported
|
|
9
|
+
* Timeout supported
|
|
10
|
+
* Occupation time limit supported
|
|
11
|
+
* Execution time limit supported
|
|
12
|
+
* Pending task limit supported
|
|
13
|
+
* Domain reentrant supported
|
|
14
|
+
* 100% code coverage
|
|
15
|
+
|
|
16
|
+
## Disclaimer
|
|
17
|
+
|
|
18
|
+
I did not create this package, and I will not add any features to it myself. I was granted the ownership because it was no longer being
|
|
19
|
+
maintained, and I volunteered to fix a bug.
|
|
20
|
+
|
|
21
|
+
If you have a new feature you would like to have incorporated, please send me a PR and I will be happy to work with you and get it merged.
|
|
22
|
+
For any bugs, PRs are most welcome but when possible I will try to get them resolved as soon as possible.
|
|
23
|
+
|
|
24
|
+
## Why do you need locking on single threaded nodejs?
|
|
25
|
+
|
|
26
|
+
Nodejs is single threaded, and the code execution never gets interrupted inside an event loop, so locking is unnecessary? This is true ONLY IF your critical section can be executed inside a single event loop.
|
|
27
|
+
However, if you have any async code inside your critical section (it can be simply triggered by any I/O operation, or timer), your critical logic will across multiple event loops, therefore it's not concurrency safe!
|
|
28
|
+
|
|
29
|
+
Consider the following code
|
|
30
|
+
```js
|
|
31
|
+
redis.get('key', function(err, value) {
|
|
32
|
+
redis.set('key', value * 2);
|
|
33
|
+
});
|
|
34
|
+
```
|
|
35
|
+
The above code simply multiply a redis key by 2.
|
|
36
|
+
However, if two users run concurrently, the execution order may like this
|
|
37
|
+
```
|
|
38
|
+
user1: redis.get('key') -> 1
|
|
39
|
+
user2: redis.get('key') -> 1
|
|
40
|
+
user1: redis.set('key', 1 x 2) -> 2
|
|
41
|
+
user2: redis.set('key', 1 x 2) -> 2
|
|
42
|
+
```
|
|
43
|
+
Obviously it's not what you expected
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
With asyncLock, you can easily write your async critical section
|
|
47
|
+
```js
|
|
48
|
+
lock.acquire('key', function(cb) {
|
|
49
|
+
// Concurrency safe
|
|
50
|
+
redis.get('key', function(err, value) {
|
|
51
|
+
redis.set('key', value * 2, cb);
|
|
52
|
+
});
|
|
53
|
+
}, function(err, ret) {
|
|
54
|
+
});
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
## Get Started
|
|
58
|
+
|
|
59
|
+
```js
|
|
60
|
+
var AsyncLock = require('async-lock');
|
|
61
|
+
var lock = new AsyncLock();
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* @param {String|Array} key resource key or keys to lock
|
|
65
|
+
* @param {function} fn execute function
|
|
66
|
+
* @param {function} cb (optional) callback function, otherwise will return a promise
|
|
67
|
+
* @param {Object} opts (optional) options
|
|
68
|
+
*/
|
|
69
|
+
lock.acquire(key, function(done) {
|
|
70
|
+
// async work
|
|
71
|
+
done(err, ret);
|
|
72
|
+
}, function(err, ret) {
|
|
73
|
+
// lock released
|
|
74
|
+
}, opts);
|
|
75
|
+
|
|
76
|
+
// Promise mode
|
|
77
|
+
lock.acquire(key, function() {
|
|
78
|
+
// return value or promise
|
|
79
|
+
}, opts).then(function() {
|
|
80
|
+
// lock released
|
|
81
|
+
});
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
## Error Handling
|
|
85
|
+
|
|
86
|
+
```js
|
|
87
|
+
// Callback mode
|
|
88
|
+
lock.acquire(key, function(done) {
|
|
89
|
+
done(new Error('error'));
|
|
90
|
+
}, function(err, ret) {
|
|
91
|
+
console.log(err.message) // output: error
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
// Promise mode
|
|
95
|
+
lock.acquire(key, function() {
|
|
96
|
+
throw new Error('error');
|
|
97
|
+
}).catch(function(err) {
|
|
98
|
+
console.log(err.message) // output: error
|
|
99
|
+
});
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
## Acquire multiple keys
|
|
103
|
+
|
|
104
|
+
```js
|
|
105
|
+
lock.acquire([key1, key2], fn, cb);
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
## Domain reentrant lock
|
|
109
|
+
|
|
110
|
+
Lock is reentrant in the same domain
|
|
111
|
+
|
|
112
|
+
```js
|
|
113
|
+
var domain = require('domain');
|
|
114
|
+
var lock = new AsyncLock({domainReentrant : true});
|
|
115
|
+
|
|
116
|
+
var d = domain.create();
|
|
117
|
+
d.run(function() {
|
|
118
|
+
lock.acquire('key', function() {
|
|
119
|
+
//Enter lock
|
|
120
|
+
return lock.acquire('key', function() {
|
|
121
|
+
//Enter same lock twice
|
|
122
|
+
});
|
|
123
|
+
});
|
|
124
|
+
});
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
## Options
|
|
128
|
+
|
|
129
|
+
```js
|
|
130
|
+
// Specify timeout - max amount of time an item can remain in the queue before acquiring the lock
|
|
131
|
+
var lock = new AsyncLock({timeout: 5000});
|
|
132
|
+
lock.acquire(key, fn, function(err, ret) {
|
|
133
|
+
// timed out error will be returned here if lock not acquired in given time
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
// Specify max occupation time - max amount of time allowed between entering the queue and completing execution
|
|
137
|
+
var lock = new AsyncLock({maxOccupationTime: 3000});
|
|
138
|
+
lock.acquire(key, fn, function(err, ret) {
|
|
139
|
+
// occupation time exceeded error will be returned here if job not completed in given time
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
// Specify max execution time - max amount of time allowed between acquiring the lock and completing execution
|
|
143
|
+
var lock = new AsyncLock({maxExecutionTime: 3000});
|
|
144
|
+
lock.acquire(key, fn, function(err, ret) {
|
|
145
|
+
// execution time exceeded error will be returned here if job not completed in given time
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
// Set max pending tasks - max number of tasks allowed in the queue at a time
|
|
149
|
+
var lock = new AsyncLock({maxPending: 1000});
|
|
150
|
+
lock.acquire(key, fn, function(err, ret) {
|
|
151
|
+
// Handle too much pending error
|
|
152
|
+
})
|
|
153
|
+
|
|
154
|
+
// Whether there is any running or pending async function
|
|
155
|
+
lock.isBusy();
|
|
156
|
+
|
|
157
|
+
// Use your own promise library instead of the global Promise variable
|
|
158
|
+
var lock = new AsyncLock({Promise: require('bluebird')}); // Bluebird
|
|
159
|
+
var lock = new AsyncLock({Promise: require('q')}); // Q
|
|
160
|
+
|
|
161
|
+
// Add a task to the front of the queue waiting for a given lock
|
|
162
|
+
lock.acquire(key, fn1, cb); // runs immediately
|
|
163
|
+
lock.acquire(key, fn2, cb); // added to queue
|
|
164
|
+
lock.acquire(key, priorityFn, cb, {skipQueue: true}); // jumps queue and runs before fn2
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
## Changelog
|
|
168
|
+
|
|
169
|
+
See [Changelog](./History.md)
|
|
170
|
+
|
|
171
|
+
## Issues
|
|
172
|
+
|
|
173
|
+
See [issue tracker](https://github.com/rogierschouten/async-lock/issues).
|
|
174
|
+
|
|
175
|
+
## License
|
|
176
|
+
|
|
177
|
+
MIT, see [LICENSE](./LICENSE)
|