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:
commit
6b98f04983
|
@ -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); } ();
|
||||||
}
|
}
|
||||||
|
|
50
tests/vibe.core.core.1742.d
Normal file
50
tests/vibe.core.core.1742.d
Normal 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();
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue