diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2020-12-18 11:22:42 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2020-12-18 11:22:42 -0300 |
commit | 409256b7849ec5ab3296cb0ab9eba3d65955d5ea (patch) | |
tree | 13d6327093e900cab0b23c4d09f344a281630c73 /testes/coroutine.lua | |
parent | b17178b27a55bd5eeb51538bec935972fd58f1ea (diff) | |
download | lua-409256b7849ec5ab3296cb0ab9eba3d65955d5ea.tar.gz lua-409256b7849ec5ab3296cb0ab9eba3d65955d5ea.tar.bz2 lua-409256b7849ec5ab3296cb0ab9eba3d65955d5ea.zip |
'coroutine.close'/'lua_resetthread' report original errors
Besides errors in closing methods, 'coroutine.close' and
'lua_resetthread' also consider the original error that stopped the
thread, if any.
Diffstat (limited to 'testes/coroutine.lua')
-rw-r--r-- | testes/coroutine.lua | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/testes/coroutine.lua b/testes/coroutine.lua index 5b927151..aaf565fb 100644 --- a/testes/coroutine.lua +++ b/testes/coroutine.lua | |||
@@ -134,7 +134,8 @@ do | |||
134 | local co = coroutine.create(print) | 134 | local co = coroutine.create(print) |
135 | assert(coroutine.resume(co, "testing 'coroutine.close'")) | 135 | assert(coroutine.resume(co, "testing 'coroutine.close'")) |
136 | assert(coroutine.status(co) == "dead") | 136 | assert(coroutine.status(co) == "dead") |
137 | assert(coroutine.close(co)) | 137 | local st, msg = coroutine.close(co) |
138 | assert(st and msg == nil) | ||
138 | 139 | ||
139 | -- cannot close the running coroutine | 140 | -- cannot close the running coroutine |
140 | local st, msg = pcall(coroutine.close, coroutine.running()) | 141 | local st, msg = pcall(coroutine.close, coroutine.running()) |
@@ -151,6 +152,13 @@ do | |||
151 | -- to-be-closed variables in coroutines | 152 | -- to-be-closed variables in coroutines |
152 | local X | 153 | local X |
153 | 154 | ||
155 | -- closing a coroutine after an error | ||
156 | local co = coroutine.create(error) | ||
157 | local st, msg = coroutine.resume(co, 100) | ||
158 | assert(not st and msg == 100) | ||
159 | st, msg = coroutine.close(co) | ||
160 | assert(not st and msg == 100) | ||
161 | |||
154 | co = coroutine.create(function () | 162 | co = coroutine.create(function () |
155 | local x <close> = func2close(function (self, err) | 163 | local x <close> = func2close(function (self, err) |
156 | assert(err == nil); X = false | 164 | assert(err == nil); X = false |