Skip to content

Commit 3cb9f20

Browse files
fix(overmind): fix async operator issue
1 parent 1417216 commit 3cb9f20

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

packages/node_modules/overmind/src/operator.ts

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,6 @@ export function stopDebugOperator(
3737
}
3838

3939
if (value instanceof Promise) {
40-
context.execution.emit(EventType.OPERATOR_ASYNC, {
41-
...context.execution,
42-
isAsync: true,
43-
})
4440
value
4541
.then((promiseValue) => {
4642
context.execution.emit(EventType.OPERATOR_END, {
@@ -127,6 +123,12 @@ export function createOperator<ThisConfig extends IConfiguration>(
127123
const operator = (err, context, next, final) => {
128124
startDebugOperator(type, name, context)
129125
try {
126+
let asyncTimeout = setTimeout(() => {
127+
context.execution.emit(EventType.OPERATOR_ASYNC, {
128+
...context.execution,
129+
isAsync: true,
130+
})
131+
})
130132
cb(
131133
err,
132134
{
@@ -136,6 +138,7 @@ export function createOperator<ThisConfig extends IConfiguration>(
136138
},
137139
context.value,
138140
(err, value, options = {}) => {
141+
clearTimeout(asyncTimeout)
139142
if (options.path) {
140143
const newContext = createContext(
141144
context,
@@ -156,6 +159,7 @@ export function createOperator<ThisConfig extends IConfiguration>(
156159
}
157160
},
158161
(err, value) => {
162+
clearTimeout(asyncTimeout)
159163
stopDebugOperator(context, value, {
160164
isIntercepted: true,
161165
})
@@ -205,6 +209,12 @@ export function createMutationOperator<ThisConfig extends IConfiguration>(
205209
})
206210
}
207211
try {
212+
let asyncTimeout = setTimeout(() => {
213+
context.execution.emit(EventType.OPERATOR_ASYNC, {
214+
...context.execution,
215+
isAsync: true,
216+
})
217+
})
208218
cb(
209219
err,
210220
{
@@ -216,12 +226,14 @@ export function createMutationOperator<ThisConfig extends IConfiguration>(
216226
? context.value
217227
: context.execution.scopeValue(context.value, mutationTree),
218228
(err, value, options = {}) => {
229+
clearTimeout(asyncTimeout)
219230
stopDebugOperator(context, value, {
220231
isSkipped: options.isSkipped,
221232
})
222233
next(err, createContext(context, value))
223234
},
224235
(err, value) => {
236+
clearTimeout(asyncTimeout)
225237
stopDebugOperator(context, value, {
226238
isIntercepted: true,
227239
})

0 commit comments

Comments
 (0)