diff --git a/core/queue.hh b/core/queue.hh index c9bc0e28b3..9ba1c53afc 100644 --- a/core/queue.hh +++ b/core/queue.hh @@ -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 pop_eventually(); }; template @@ -97,6 +101,18 @@ T queue::pop() { return data; } +template +inline +future queue::pop_eventually() { + if (empty()) { + return not_empty().then([this] { + return make_ready_future(pop()); + }); + } else { + return make_ready_future(pop()); + } +} + template template inline