mirror of
https://github.com/matrix-construct/construct
synced 2024-12-27 07:54:05 +01:00
ircd::ctx: yield the promise-notifying ctx until any then() has posted.
This commit is contained in:
parent
db93acf8fb
commit
8d91c90574
1 changed files with 12 additions and 2 deletions
|
@ -104,11 +104,21 @@ ircd::ctx::notify(shared_state<T> &st)
|
|||
return;
|
||||
}
|
||||
|
||||
ircd::post([&st]
|
||||
// Need a fresh stack to execute then(), not this ctx's.
|
||||
ircd::post([&st]() noexcept
|
||||
{
|
||||
assert(bool(st.then));
|
||||
st.cond.notify_all();
|
||||
st.then(st);
|
||||
st.then = {};
|
||||
st.cond.notify_all();
|
||||
});
|
||||
|
||||
// If we don't hold the ctx here then it's too easy to destroy the future
|
||||
// between now and when then() posts. This is completely effective if the
|
||||
// future is on this ctx as long as then() itself doesn't hose it.
|
||||
st.cond.wait([&st]
|
||||
{
|
||||
return !bool(st.then);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue