Rename Active / Dead to better reflect their behavior
This commit is contained in:
parent
b458f91aac
commit
820c38e806
13
src/lua.rs
13
src/lua.rs
|
@ -765,15 +765,14 @@ impl<'lua> Function<'lua> {
|
||||||
/// Status of a Lua thread (or coroutine).
|
/// Status of a Lua thread (or coroutine).
|
||||||
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
|
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
|
||||||
pub enum ThreadStatus {
|
pub enum ThreadStatus {
|
||||||
/// The thread has finished executing.
|
/// The thread was just created, or is suspended because it has called `coroutine.yield`.
|
||||||
Dead,
|
|
||||||
/// The thread was just created, is currently running or is suspended because it has called
|
|
||||||
/// `coroutine.yield`.
|
|
||||||
///
|
///
|
||||||
/// If a thread is in this state, it can be resumed by calling [`Thread::resume`].
|
/// If a thread is in this state, it can be resumed by calling [`Thread::resume`].
|
||||||
///
|
///
|
||||||
/// [`Thread::resume`]: struct.Thread.html#method.resume
|
/// [`Thread::resume`]: struct.Thread.html#method.resume
|
||||||
Active,
|
Resumable,
|
||||||
|
/// Either the thread has finished executing, or the thread is currently running.
|
||||||
|
Unresumable,
|
||||||
/// The thread has raised a Lua error during execution.
|
/// The thread has raised a Lua error during execution.
|
||||||
Error,
|
Error,
|
||||||
}
|
}
|
||||||
|
@ -886,9 +885,9 @@ impl<'lua> Thread<'lua> {
|
||||||
if status != ffi::LUA_OK && status != ffi::LUA_YIELD {
|
if status != ffi::LUA_OK && status != ffi::LUA_YIELD {
|
||||||
ThreadStatus::Error
|
ThreadStatus::Error
|
||||||
} else if status == ffi::LUA_YIELD || ffi::lua_gettop(thread_state) > 0 {
|
} else if status == ffi::LUA_YIELD || ffi::lua_gettop(thread_state) > 0 {
|
||||||
ThreadStatus::Active
|
ThreadStatus::Resumable
|
||||||
} else {
|
} else {
|
||||||
ThreadStatus::Dead
|
ThreadStatus::Unresumable
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
16
src/tests.rs
16
src/tests.rs
|
@ -599,17 +599,17 @@ fn test_thread() {
|
||||||
).unwrap(),
|
).unwrap(),
|
||||||
);
|
);
|
||||||
|
|
||||||
assert_eq!(thread.status(), ThreadStatus::Active);
|
assert_eq!(thread.status(), ThreadStatus::Resumable);
|
||||||
assert_eq!(thread.resume::<_, i64>(0).unwrap(), 0);
|
assert_eq!(thread.resume::<_, i64>(0).unwrap(), 0);
|
||||||
assert_eq!(thread.status(), ThreadStatus::Active);
|
assert_eq!(thread.status(), ThreadStatus::Resumable);
|
||||||
assert_eq!(thread.resume::<_, i64>(1).unwrap(), 1);
|
assert_eq!(thread.resume::<_, i64>(1).unwrap(), 1);
|
||||||
assert_eq!(thread.status(), ThreadStatus::Active);
|
assert_eq!(thread.status(), ThreadStatus::Resumable);
|
||||||
assert_eq!(thread.resume::<_, i64>(2).unwrap(), 3);
|
assert_eq!(thread.resume::<_, i64>(2).unwrap(), 3);
|
||||||
assert_eq!(thread.status(), ThreadStatus::Active);
|
assert_eq!(thread.status(), ThreadStatus::Resumable);
|
||||||
assert_eq!(thread.resume::<_, i64>(3).unwrap(), 6);
|
assert_eq!(thread.resume::<_, i64>(3).unwrap(), 6);
|
||||||
assert_eq!(thread.status(), ThreadStatus::Active);
|
assert_eq!(thread.status(), ThreadStatus::Resumable);
|
||||||
assert_eq!(thread.resume::<_, i64>(4).unwrap(), 10);
|
assert_eq!(thread.resume::<_, i64>(4).unwrap(), 10);
|
||||||
assert_eq!(thread.status(), ThreadStatus::Dead);
|
assert_eq!(thread.status(), ThreadStatus::Unresumable);
|
||||||
|
|
||||||
let accumulate = lua.create_thread(
|
let accumulate = lua.create_thread(
|
||||||
lua.eval::<Function>(
|
lua.eval::<Function>(
|
||||||
|
@ -628,7 +628,7 @@ fn test_thread() {
|
||||||
accumulate.resume::<_, ()>(i).unwrap();
|
accumulate.resume::<_, ()>(i).unwrap();
|
||||||
}
|
}
|
||||||
assert_eq!(accumulate.resume::<_, i64>(4).unwrap(), 10);
|
assert_eq!(accumulate.resume::<_, i64>(4).unwrap(), 10);
|
||||||
assert_eq!(accumulate.status(), ThreadStatus::Active);
|
assert_eq!(accumulate.status(), ThreadStatus::Resumable);
|
||||||
assert!(accumulate.resume::<_, ()>("error").is_err());
|
assert!(accumulate.resume::<_, ()>("error").is_err());
|
||||||
assert_eq!(accumulate.status(), ThreadStatus::Error);
|
assert_eq!(accumulate.status(), ThreadStatus::Error);
|
||||||
|
|
||||||
|
@ -642,7 +642,7 @@ fn test_thread() {
|
||||||
"#,
|
"#,
|
||||||
None,
|
None,
|
||||||
).unwrap();
|
).unwrap();
|
||||||
assert_eq!(thread.status(), ThreadStatus::Active);
|
assert_eq!(thread.status(), ThreadStatus::Resumable);
|
||||||
assert_eq!(thread.resume::<_, i64>(()).unwrap(), 42);
|
assert_eq!(thread.resume::<_, i64>(()).unwrap(), 42);
|
||||||
|
|
||||||
let thread: Thread = lua.eval(
|
let thread: Thread = lua.eval(
|
||||||
|
|
Loading…
Reference in New Issue