Avoid bogus "A task cannot interrupt itself" assertion failure.
Calling Task.interrupt() on a task that is already finished, but ran on the same fiber would trigger an assertion failure instead of returning silently.
This commit is contained in:
parent
a170973cfd
commit
3182160a9a
|
@ -97,7 +97,14 @@ struct Task {
|
|||
|
||||
void join() @trusted { if (m_fiber) m_fiber.join!true(m_taskCounter); }
|
||||
void joinUninterruptible() @trusted nothrow { if (m_fiber) m_fiber.join!false(m_taskCounter); }
|
||||
void interrupt() @trusted nothrow { if (m_fiber) m_fiber.interrupt(m_taskCounter); }
|
||||
void interrupt() @trusted nothrow { if (m_fiber && this.running) m_fiber.interrupt(m_taskCounter); }
|
||||
|
||||
unittest { // regression test for bogus "task cannot interrupt itself"
|
||||
import vibe.core.core : runTask;
|
||||
auto t = runTask({});
|
||||
t.join();
|
||||
runTask({ t.interrupt(); }).join();
|
||||
}
|
||||
|
||||
string toString() const @safe { import std.string; return format("%s:%s", () @trusted { return cast(void*)m_fiber; } (), m_taskCounter); }
|
||||
|
||||
|
@ -138,7 +145,6 @@ struct Task {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
/** Settings to control the behavior of newly started tasks.
|
||||
*/
|
||||
struct TaskSettings {
|
||||
|
|
Loading…
Reference in a new issue