gcf-common-lib 0.23.13 → 0.23.15
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/package.json +1 -1
- package/src/mongo-lock.js +3 -3
- package/src/mongo-lock.ts +4 -4
package/package.json
CHANGED
package/src/mongo-lock.js
CHANGED
|
@@ -73,8 +73,8 @@ class MongoLock {
|
|
|
73
73
|
return (0, rxjs_1.lastValueFrom)((0, rxjs_1.defer)(() => (0, rxjs_1.from)(this.acquireLock(name, ttlSeconds))).pipe((0, rxjs_1.map)(locked => {
|
|
74
74
|
// console.log(locked);
|
|
75
75
|
if (!locked)
|
|
76
|
-
throw
|
|
77
|
-
}), wait ? (0, rxjs_1.retry)({ count, delay }) : rxjs_1.identity, (0, rxjs_1.switchMap)(() => __awaiter(this, void 0, void 0, function* () { return fn().finally(() => this.releaseLock(name).catch(noop_1.default)); }))));
|
|
76
|
+
throw new Error('Could not acquire lock');
|
|
77
|
+
}), wait ? (0, rxjs_1.retry)({ count, delay }) : (0, rxjs_1.tap)(rxjs_1.identity), (0, rxjs_1.switchMap)(() => __awaiter(this, void 0, void 0, function* () { return fn().finally(() => this.releaseLock(name).catch(noop_1.default)); }))));
|
|
78
78
|
});
|
|
79
79
|
}
|
|
80
80
|
checkLock(name, waitSeconds = 0) {
|
|
@@ -86,7 +86,7 @@ class MongoLock {
|
|
|
86
86
|
// console.log(lock);
|
|
87
87
|
if (lock)
|
|
88
88
|
throw lock;
|
|
89
|
-
}), waitSeconds > 0 ? (0, rxjs_1.retry)({ count, delay }) : rxjs_1.identity));
|
|
89
|
+
}), waitSeconds > 0 ? (0, rxjs_1.retry)({ count, delay }) : (0, rxjs_1.tap)(rxjs_1.identity)));
|
|
90
90
|
});
|
|
91
91
|
}
|
|
92
92
|
}
|
package/src/mongo-lock.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { MongoClient, MongoError } from 'mongodb';
|
|
2
2
|
import moment from 'moment';
|
|
3
3
|
import noop from 'lodash/noop';
|
|
4
|
-
import { defer, from, identity, lastValueFrom, map, retry, switchMap } from 'rxjs';
|
|
4
|
+
import { defer, from, identity, lastValueFrom, map, of, retry, switchMap, tap } from 'rxjs';
|
|
5
5
|
import { MongoHelper } from './mongo-helper';
|
|
6
6
|
|
|
7
7
|
export class MongoLock {
|
|
@@ -59,9 +59,9 @@ export class MongoLock {
|
|
|
59
59
|
defer(() => from(this.acquireLock(name, ttlSeconds))).pipe(
|
|
60
60
|
map(locked => {
|
|
61
61
|
// console.log(locked);
|
|
62
|
-
if (!locked) throw
|
|
62
|
+
if (!locked) throw new Error('Could not acquire lock');
|
|
63
63
|
}),
|
|
64
|
-
wait ? retry({ count, delay }) : identity,
|
|
64
|
+
wait ? retry({ count, delay }) : tap(identity),
|
|
65
65
|
switchMap(async () => fn().finally(() => this.releaseLock(name).catch(noop))),
|
|
66
66
|
),
|
|
67
67
|
);
|
|
@@ -78,7 +78,7 @@ export class MongoLock {
|
|
|
78
78
|
// console.log(lock);
|
|
79
79
|
if (lock) throw lock;
|
|
80
80
|
}),
|
|
81
|
-
waitSeconds > 0 ? retry({ count, delay }) : identity,
|
|
81
|
+
waitSeconds > 0 ? retry({ count, delay }) : tap(identity),
|
|
82
82
|
),
|
|
83
83
|
);
|
|
84
84
|
}
|