wpiutil: Change uv::AsyncFunction to use promise/future.

This allows the called function to pass along the promise to another
asynchronous callback.

To avoid memory allocations, add a home-rolled, simplified, non-allocating
version of std::promise and std::future as wpi::promise and wpi::future.
This commit is contained in:
Peter Johnson
2018-09-05 23:01:57 -07:00
parent 11e5faf469
commit 1a7a0db1ff
6 changed files with 1237 additions and 148 deletions

View File

@@ -25,7 +25,10 @@ class EventLoopRunner::Thread : public SafeThread {
// run function
m_doExec = UvExecFunc::Create(
m_loop, [loop = m_loop.get()](LoopFunc func) { func(*loop); });
m_loop, [loop = m_loop.get()](auto out, LoopFunc func) {
func(*loop);
out.set_value();
});
}
void Main() {
@@ -51,7 +54,7 @@ EventLoopRunner::~EventLoopRunner() {
void EventLoopRunner::ExecAsync(LoopFunc func) {
if (auto thr = m_owner.GetThread()) {
if (auto doExec = thr->m_doExec.lock()) {
doExec->Send(func);
doExec->Call(func);
}
}
}