From 57bc48ddbb1ddceff902ff2d01d9a5476d0656c9 Mon Sep 17 00:00:00 2001 From: Tomasz Grabiec Date: Wed, 17 Sep 2014 17:03:30 +0200 Subject: [PATCH] core: add queue::pop_eventually() It's an asynchronous version of blocking pop(). --- core/queue.hh | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) 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