core: add queue::pop_eventually()

It's an asynchronous version of blocking pop().
This commit is contained in:
Tomasz Grabiec
2014-09-17 17:03:30 +02:00
parent b27b200e94
commit 57bc48ddbb

View File

@@ -48,6 +48,10 @@ public:
// Returns a future<> that becomes available when push() can be called.
future<> not_full();
// Pops element now or when ther is some. Returns a future that becomes
// available when some element is available.
future<T> pop_eventually();
};
template <typename T>
@@ -97,6 +101,18 @@ T queue<T>::pop() {
return data;
}
template <typename T>
inline
future<T> queue<T>::pop_eventually() {
if (empty()) {
return not_empty().then([this] {
return make_ready_future<T>(pop());
});
} else {
return make_ready_future<T>(pop());
}
}
template <typename T>
template <typename Func>
inline