Merge pull request #163 from vibe-d/issue157-empty-consumeOne-on-closed-channel

Fix empty-consumeOne channel usage pattern for a single consumer
This commit is contained in:
Leonid Kramer 2019-06-20 09:31:13 +02:00 committed by GitHub
commit c39fdb2208
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 42 additions and 3 deletions

View file

@ -0,0 +1,29 @@
/+ dub.sdl:
name "tests"
dependency "vibe-core" path=".."
+/
module tests;
import vibe.core.channel;
import vibe.core.core;
import core.time;
void main()
{
auto ch = createChannel!int();
auto p = runTask({
sleep(1.seconds);
ch.close();
});
auto c = runTask({
while (!ch.empty) {
try ch.consumeOne();
catch (Exception e) assert(false, e.msg);
}
});
p.join();
c.join();
}