diff options
| author | Alexey Melnichuk <mimir@newmail.ru> | 2014-02-04 11:06:17 +0400 |
|---|---|---|
| committer | Alexey Melnichuk <mimir@newmail.ru> | 2014-02-04 11:06:17 +0400 |
| commit | cef9a7a112a8322e2c6498021df59e4a8f7b5246 (patch) | |
| tree | 5a885427afef52cbd3067c79b1f24406e42ecf87 /test | |
| parent | d35bf824e0dd9c3584d1587b5ec662a0fcf71bfe (diff) | |
| download | lua-llthreads2-cef9a7a112a8322e2c6498021df59e4a8f7b5246.tar.gz lua-llthreads2-cef9a7a112a8322e2c6498021df59e4a8f7b5246.tar.bz2 lua-llthreads2-cef9a7a112a8322e2c6498021df59e4a8f7b5246.zip | |
Add. `thread:alive()` method.
Diffstat (limited to 'test')
| -rw-r--r-- | test/test_alive.lua | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/test/test_alive.lua b/test/test_alive.lua new file mode 100644 index 0000000..ecce163 --- /dev/null +++ b/test/test_alive.lua | |||
| @@ -0,0 +1,35 @@ | |||
| 1 | local llthreads = require"llthreads" | ||
| 2 | local utils = require "utils" | ||
| 3 | local sleep = utils.sleep | ||
| 4 | |||
| 5 | local include = utils.thread_init .. [[ | ||
| 6 | local llthreads = require"llthreads" | ||
| 7 | local sleep = require "utils".sleep | ||
| 8 | ]] | ||
| 9 | |||
| 10 | local thread = llthreads.new(include .. [[ | ||
| 11 | sleep(5) | ||
| 12 | return 1,2,3 | ||
| 13 | ]]) | ||
| 14 | |||
| 15 | assert(nil == thread:alive()) | ||
| 16 | |||
| 17 | thread:start() | ||
| 18 | |||
| 19 | assert(true == thread:alive()) | ||
| 20 | |||
| 21 | for i = 1, 10 do | ||
| 22 | if not thread:alive() then break end | ||
| 23 | sleep(1) | ||
| 24 | end | ||
| 25 | |||
| 26 | assert(false == thread:alive()) | ||
| 27 | |||
| 28 | local ok,a,b,c = thread:join(0) | ||
| 29 | assert(ok == true) | ||
| 30 | assert(a == 1) | ||
| 31 | assert(b == 2) | ||
| 32 | assert(c == 3) | ||
| 33 | |||
| 34 | print("Done!") | ||
| 35 | |||
