gcf-common-lib 0.23.11 → 0.23.12

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "gcf-common-lib",
3
3
  "description": "",
4
- "version": "0.23.11",
4
+ "version": "0.23.12",
5
5
  "publishConfig": {
6
6
  "access": "public",
7
7
  "branches": [
package/src/mongo-lock.js CHANGED
@@ -72,10 +72,10 @@ class MongoLock {
72
72
  const delay = 200;
73
73
  const count = Math.round((1000 / delay) * ttlSeconds);
74
74
  return (0, rxjs_1.lastValueFrom)((0, rxjs_1.defer)(() => (0, rxjs_1.from)(this.acquireLock(name, ttlSeconds))).pipe((0, rxjs_1.map)(locked => {
75
- console.log(locked);
75
+ // console.log(locked);
76
76
  if (!locked)
77
77
  throw locked;
78
- }), wait ? (0, rxjs_1.retry)({ count, delay }) : rxjs_1.identity, (0, rxjs_1.switchMap)(() => fn().finally(() => this.releaseLock(name).catch(noop_1.default)))));
78
+ }), 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)); }))));
79
79
  });
80
80
  }
81
81
  }
package/src/mongo-lock.ts CHANGED
@@ -54,18 +54,18 @@ export class MongoLock {
54
54
  return collection.deleteOne({_id: name as any});
55
55
  }
56
56
 
57
- async acquireAndExecute(name: string, ttlSeconds: number, wait: boolean, fn: () => Promise<any>) {
57
+ async acquireAndExecute<T = any>(name: string, ttlSeconds: number, wait: boolean, fn: () => Promise<T>) {
58
58
  const delay = 200;
59
59
  const count = Math.round((1000 / delay) * ttlSeconds);
60
60
 
61
61
  return lastValueFrom(
62
62
  defer(() => from(this.acquireLock(name, ttlSeconds))).pipe(
63
63
  map(locked => {
64
- console.log(locked);
64
+ // console.log(locked);
65
65
  if (!locked) throw locked;
66
66
  }),
67
67
  wait ? retry({count, delay}) : identity,
68
- switchMap(() => fn().finally(() => this.releaseLock(name).catch(noop))),
68
+ switchMap(async () => fn().finally(() => this.releaseLock(name).catch(noop))),
69
69
  ),
70
70
  );
71
71
  }