Skip to content

Commit eb04520

Browse files
committed
use coroutine.status instead of lastData
1 parent fa508b4 commit eb04520

1 file changed

Lines changed: 7 additions & 10 deletions

File tree

src/lualib/Await.ts

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,24 +25,21 @@ function __TS__AsyncAwaiter(this: void, generator: (this: void) => void) {
2525
}
2626
function fulfilled(value) {
2727
try {
28-
const [running, result] = coroutine.resume(asyncCoroutine, value);
29-
step(running, result);
28+
const [_, result] = coroutine.resume(asyncCoroutine, value);
29+
step(result);
3030
} catch (e) {
3131
reject(e);
3232
}
3333
}
34-
let lastData: unknown;
35-
function step(running: boolean, result: unknown) {
36-
if (!running) {
37-
resolve(lastData);
34+
function step(result: unknown) {
35+
if (coroutine.status(asyncCoroutine) === "dead") {
36+
resolve(result);
3837
} else {
39-
// Not possible to determine if a running === true will be the last one, once it's false the data to return is lost, so save it.
40-
lastData = result;
4138
adopt(result).then(fulfilled, reason => reject(reason));
4239
}
4340
}
44-
const [running, result] = coroutine.resume(asyncCoroutine);
45-
step(running, result);
41+
const [_, result] = coroutine.resume(asyncCoroutine);
42+
step(result);
4643
});
4744
}
4845

0 commit comments

Comments
 (0)