mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-19 00:41:43 +00:00
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:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user