forked from lunarmodules/copas
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request lunarmodules#25 from Tieske/exit
Exit loop when all is done
- Loading branch information
Showing
3 changed files
with
77 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
-- tests whether the main loop automatically exits when all work is done | ||
|
||
local copas = require("copas") | ||
local socket = require("socket") | ||
|
||
copas.addthread(function() | ||
local n = 1 | ||
while n<=5 do | ||
copas.sleep(0) | ||
print(n) | ||
n=n+1 | ||
end | ||
end) | ||
|
||
print("Test 1 count to 5... then exit") | ||
copas.loop() | ||
print("Test 1 done") | ||
|
||
local server, err = socket.bind("*", 20000) | ||
|
||
copas.addserver(server, function(skt) | ||
print(copas.receive(skt)) | ||
copas.removeserver(server) | ||
end) | ||
|
||
copas.addthread(function() | ||
copas.sleep(1) | ||
local skt, err = socket.connect("localhost", 20000) | ||
print(copas.send(skt, "Hello world!\n")) | ||
end) | ||
|
||
print("Test 2 send and receive some... then exit") | ||
copas.loop() | ||
print("Test 2 done") | ||
|