Merge pull request #12 from DBankov/Fix-for-#11

Fix for #11. Cross port of fix for #1742 from vibe.d
This commit is contained in:
Sönke Ludwig 2017-04-15 00:44:54 +02:00 committed by GitHub
commit 6b98f04983
2 changed files with 51 additions and 1 deletions

View file

@ -56,7 +56,7 @@ struct Task {
auto fiber = () @trusted { return Fiber.getThis(); } (); auto fiber = () @trusted { return Fiber.getThis(); } ();
if (!fiber) return Task.init; if (!fiber) return Task.init;
auto tfiber = cast(TaskFiber)fiber; auto tfiber = cast(TaskFiber)fiber;
assert(tfiber !is null, "Invalid or null fiber used to construct Task handle."); if (!tfiber) return Task.init;
// FIXME: returning a non-.init handle for a finished task might break some layered logic // FIXME: returning a non-.init handle for a finished task might break some layered logic
return () @trusted { return Task(tfiber, tfiber.m_taskCounter); } (); return () @trusted { return Task(tfiber, tfiber.m_taskCounter); } ();
} }

View file

@ -0,0 +1,50 @@
/+ dub.sdl:
name "tests"
description "Semaphore hang"
dependency "vibe-core" path="../"
+/
module test;
import std.stdio;
import std.socket;
import std.datetime;
import std.functional;
import core.time;
import vibe.core.core;
import vibe.core.log;
import vibe.core.concurrency;
import vibe.core.connectionpool;
class Conn {}
void main()
{
auto g = new Generator!int({
auto t = runTask({});
t.join();
yield(2);
});
assert(!g.empty);
assert(g.front == 2);
g.popFront();
assert(g.empty);
runTask({
auto g2 = new Generator!int({
auto t = runTask({});
t.join();
yield(1);
});
assert(!g2.empty);
assert(g2.front == 1);
g2.popFront();
assert(g2.empty);
exitEventLoop();
});
setTimer(5.seconds, {
assert(false, "Test has hung.");
});
runApplication();
}