@powfix/core-js 0.13.0 → 0.13.1

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.
@@ -17,6 +17,11 @@ declare class TransactionManager {
17
17
  removeListener<T extends EventEmitter.EventNames<TransactionManagerEventTypes>>(event: T, fn: EventEmitter.EventListener<TransactionManagerEventTypes, T>): void;
18
18
  add(transaction: Transaction, option?: TransactionManagerAddOption): void;
19
19
  remove(transaction: Transaction): void;
20
+ flush(action?: TransactionManagerTimeoutAction): Promise<PromiseSettledResult<{
21
+ handled: boolean;
22
+ transaction: Transaction;
23
+ }>[]>;
24
+ private execute;
20
25
  private timeout;
21
26
  private afterCommit;
22
27
  }
@@ -56,29 +56,43 @@ class TransactionManager {
56
56
  const action = (_a = option === null || option === void 0 ? void 0 : option.timeoutAction) !== null && _a !== void 0 ? _a : TransactionManager.DEFAULT_ACTION;
57
57
  const timeout = (_b = option === null || option === void 0 ? void 0 : option.timeout) !== null && _b !== void 0 ? _b : TransactionManager.DEFAULT_TIMEOUT;
58
58
  const handler = setTimeout(this.timeout.bind(this), timeout, transaction, action);
59
- this.transactionTimeoutMap.set(transaction, handler);
59
+ this.transactionTimeoutMap.set(transaction, {
60
+ handler,
61
+ action,
62
+ });
60
63
  // Callback
61
64
  transaction.afterCommit(this.afterCommit.bind(this));
62
65
  }
63
66
  remove(transaction) {
64
67
  const transactionTimeout = this.transactionTimeoutMap.get(transaction);
65
68
  if (transactionTimeout != null) {
66
- clearTimeout(transactionTimeout);
69
+ clearTimeout(transactionTimeout.handler);
67
70
  this.transactionTimeoutMap.delete(transaction);
68
71
  if (this.logLevel >= constants_1.TransactionManagerLogLevel.VERBOSE) {
69
72
  console.log(LOG_TAG, this.getTransactionLogArg(transaction), 'removed');
70
73
  }
71
74
  }
72
75
  }
73
- timeout(transaction, action) {
76
+ flush(action) {
77
+ return Promise.allSettled(Array.from(this.transactionTimeoutMap.entries()).map(([transaction, transactionTimeout]) => __awaiter(this, void 0, void 0, function* () {
78
+ const handled = yield this.execute(transaction, action !== null && action !== void 0 ? action : transactionTimeout.action, 'flush');
79
+ this.remove(transaction);
80
+ return {
81
+ handled,
82
+ transaction,
83
+ };
84
+ })));
85
+ }
86
+ execute(transaction, action, reason) {
74
87
  return __awaiter(this, void 0, void 0, function* () {
88
+ let handled = false;
75
89
  const finished = transaction === null || transaction === void 0 ? void 0 : transaction.finished;
76
90
  if (finished != null) {
77
91
  if (this.logLevel >= constants_1.TransactionManagerLogLevel.VERBOSE) {
78
- console.log(LOG_TAG, this.getTransactionLogArg(transaction), `is already handled(${finished}) after timeout`);
92
+ console.log(LOG_TAG, this.getTransactionLogArg(transaction), `is already handled(${finished}) after`, reason);
79
93
  }
80
94
  this.remove(transaction);
81
- return;
95
+ return handled;
82
96
  }
83
97
  try {
84
98
  let finished;
@@ -100,10 +114,10 @@ class TransactionManager {
100
114
  break;
101
115
  }
102
116
  }
103
- const handled = finished != null;
117
+ handled = finished != null;
104
118
  if (finished != null) {
105
119
  if (this.logLevel >= constants_1.TransactionManagerLogLevel.ERROR) {
106
- console.error(LOG_TAG, this.getTransactionLogArg(transaction), `handled(${finished}) after timeout`);
120
+ console.error(LOG_TAG, this.getTransactionLogArg(transaction), `handled(${finished}) after`, reason);
107
121
  }
108
122
  }
109
123
  else {
@@ -111,12 +125,20 @@ class TransactionManager {
111
125
  console.error(LOG_TAG, this.getTransactionLogArg(transaction), `not handled 🚫`);
112
126
  }
113
127
  }
114
- // Emit
115
- this.emitter.emit('onUnhandledTransaction', transaction, handled);
116
128
  }
117
129
  catch (e) {
118
130
  console.error(e);
119
131
  }
132
+ finally {
133
+ this.remove(transaction);
134
+ }
135
+ return handled;
136
+ });
137
+ }
138
+ timeout(transaction, action) {
139
+ return __awaiter(this, void 0, void 0, function* () {
140
+ const handled = yield this.execute(transaction, action, 'timeout');
141
+ this.emitter.emit('onUnhandledTransaction', transaction, handled);
120
142
  });
121
143
  }
122
144
  afterCommit(transaction) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@powfix/core-js",
3
- "version": "0.13.0",
3
+ "version": "0.13.1",
4
4
  "description": "core package",
5
5
  "author": "Kwon Kyung-Min <powfix@gmail.com>",
6
6
  "private": false,