mirror of
https://github.com/scylladb/scylladb.git
synced 2026-04-26 19:35:12 +00:00
core: add queue::pop_eventually()
It's an asynchronous version of blocking pop().
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user