File tree Expand file tree Collapse file tree 2 files changed +11
-17
lines changed Expand file tree Collapse file tree 2 files changed +11
-17
lines changed Original file line number Diff line number Diff line change 1
1
2
- local err_symbol = {}
3
-
4
2
local function await (p )
5
3
assert (coroutine.running (), " running inside a Promise.async() call" )
6
4
local result = nil
@@ -18,7 +16,7 @@ local function await(p)
18
16
while true do
19
17
if finished then
20
18
if err then
21
- return coroutine.yield ({ err = err , err_symbol = err_symbol })
19
+ return nil , err
22
20
else
23
21
return unpack (result )
24
22
end
@@ -42,10 +40,6 @@ function Promise.async(fn)
42
40
if not cont then
43
41
-- error in first async() level
44
42
p :reject (result )
45
- end
46
- if type (result ) == " table" and result .err_symbol == err_symbol then
47
- -- error in await() call
48
- p :reject (result .err )
49
43
return
50
44
end
51
45
minetest .after (0 , step )
Original file line number Diff line number Diff line change 32
32
33
33
mtt .register (" Promise.async with handle_async" , function ()
34
34
return Promise .async (function (await )
35
- local v = await (Promise .resolved (42 ))
35
+ local v , err = await (Promise .resolved (42 ))
36
36
assert (v == 42 )
37
- v = await (Promise .handle_async (function () return 100 end ))
37
+ assert (not err )
38
+ v , err = await (Promise .handle_async (function () return 100 end ))
38
39
assert (v == 100 )
40
+ assert (not err )
39
41
end )
40
42
end )
41
43
42
- mtt .register (" Promise.async rejected" , function (callback )
43
- local p = Promise .async (function (await )
44
- await (Promise .rejected (" my-err" ))
44
+ mtt .register (" Promise.async error propagation" , function ()
45
+ return Promise .async (function (await )
46
+ local v , err = await (Promise .rejected (" my-err" ))
47
+ assert (not v )
48
+ assert (err )
45
49
end )
46
50
47
- p :catch (function (e )
48
- assert (type (e ) == " string" )
49
- callback ()
50
- end )
51
51
end )
52
52
53
- mtt .register (" Promise.async error" , function (callback )
53
+ mtt .register (" Promise.async direct error" , function (callback )
54
54
local p = Promise .async (function ()
55
55
error (" stuff" )
56
56
end )
You can’t perform that action at this time.
0 commit comments