'coroutine.kill' renamed 'coroutine.close'

This commit is contained in:
Roberto Ierusalimschy 2019-06-03 13:11:20 -03:00
parent 4a3fd8488d
commit 514d942748
3 changed files with 29 additions and 28 deletions

View File

@ -165,7 +165,7 @@ static int luaB_corunning (lua_State *L) {
}
static int luaB_kill (lua_State *L) {
static int luaB_close (lua_State *L) {
lua_State *co = getco(L);
int status = auxstatus(L, co);
switch (status) {
@ -182,7 +182,7 @@ static int luaB_kill (lua_State *L) {
}
}
default: /* normal or running coroutine */
return luaL_error(L, "cannot kill a %s coroutine", statname[status]);
return luaL_error(L, "cannot close a %s coroutine", statname[status]);
}
}
@ -195,7 +195,7 @@ static const luaL_Reg co_funcs[] = {
{"wrap", luaB_cowrap},
{"yield", luaB_yield},
{"isyieldable", luaB_yieldable},
{"kill", luaB_kill},
{"close", luaB_close},
{NULL, NULL}
};

View File

@ -864,7 +864,7 @@ Unlike @Lid{coroutine.resume},
the function created by @Lid{coroutine.wrap}
propagates any error to the caller.
In this case,
the function also kills the coroutine @seeF{coroutine.kill}.
the function also closes the coroutine @seeF{coroutine.close}.
As an example of how coroutines work,
consider the following code:
@ -1554,7 +1554,7 @@ Similarly, if a coroutine ends with an error,
it does not unwind its stack,
so it does not close any variable.
You should either use finalizers
or call @Lid{coroutine.kill} to close the variables in these cases.
or call @Lid{coroutine.close} to close the variables in these cases.
However, note that if the coroutine was created
through @Lid{coroutine.wrap},
then its corresponding function will close all variables
@ -6351,6 +6351,18 @@ which come inside the table @defid{coroutine}.
See @See{coroutine} for a general description of coroutines.
@LibEntry{coroutine.close (co)|
Closes coroutine @id{co},
that is,
closes all its pending to-be-closed variables
and puts the coroutine in a dead state.
In case of error closing some variable,
returns @false plus the error object;
otherwise returns @true.
}
@LibEntry{coroutine.create (f)|
Creates a new coroutine, with body @id{f}.
@ -6370,17 +6382,6 @@ it is not inside a non-yieldable @N{C function}.
}
@LibEntry{coroutine.kill (co)|
Kills coroutine @id{co},
closing all its pending to-be-closed variables
and putting the coroutine in a dead state.
In case of error closing some variable,
returns @false plus the error object;
otherwise returns @true.
}
@LibEntry{coroutine.resume (co [, val1, @Cdots])|
Starts or continues the execution of coroutine @id{co}.
@ -6433,7 +6434,7 @@ extra arguments to @id{resume}.
The function returns the same values returned by @id{resume},
except the first boolean.
In case of error,
the function kills the coroutine and propagates the error.
the function closes the coroutine and propagates the error.
}

View File

@ -123,23 +123,23 @@ assert(#a == 22 and a[#a] == 79)
x, a = nil
-- coroutine kill
-- coroutine closing
do
-- ok to kill a dead coroutine
-- ok to close a dead coroutine
local co = coroutine.create(print)
assert(coroutine.resume(co, "testing 'coroutine.kill'"))
assert(coroutine.resume(co, "testing 'coroutine.close'"))
assert(coroutine.status(co) == "dead")
assert(coroutine.kill(co))
assert(coroutine.close(co))
-- cannot kill the running coroutine
local st, msg = pcall(coroutine.kill, coroutine.running())
-- cannot close the running coroutine
local st, msg = pcall(coroutine.close, coroutine.running())
assert(not st and string.find(msg, "running"))
local main = coroutine.running()
-- cannot kill a "normal" coroutine
-- cannot close a "normal" coroutine
;(coroutine.wrap(function ()
local st, msg = pcall(coroutine.kill, main)
local st, msg = pcall(coroutine.close, main)
assert(not st and string.find(msg, "normal"))
end))()
@ -159,10 +159,10 @@ do
end)
coroutine.resume(co)
assert(X)
assert(coroutine.kill(co))
assert(coroutine.close(co))
assert(not X and coroutine.status(co) == "dead")
-- error killing a coroutine
-- error closing a coroutine
co = coroutine.create(function()
local <toclose> x = func2close(function (self, err)
assert(err == nil); error(111)
@ -170,7 +170,7 @@ do
coroutine.yield()
end)
coroutine.resume(co)
local st, msg = coroutine.kill(co)
local st, msg = coroutine.close(co)
assert(not st and coroutine.status(co) == "dead" and msg == 111)
end