[geary/wip/improve-claiming-folder-session: 6/9] Add a nonblocking queue peek() method
- From: Michael Gratton <mjog src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [geary/wip/improve-claiming-folder-session: 6/9] Add a nonblocking queue peek() method
- Date: Mon, 19 Nov 2018 13:35:42 +0000 (UTC)
commit a6e0fe9255dcb43939775ecff584357c3aa4b17f
Author: Michael Gratton <mike vee net>
Date: Tue Nov 13 15:54:44 2018 +1100
Add a nonblocking queue peek() method
src/engine/nonblocking/nonblocking-queue.vala | 18 +++++++++++++++++-
1 file changed, 17 insertions(+), 1 deletion(-)
---
diff --git a/src/engine/nonblocking/nonblocking-queue.vala b/src/engine/nonblocking/nonblocking-queue.vala
index c7924318..cd6d920b 100644
--- a/src/engine/nonblocking/nonblocking-queue.vala
+++ b/src/engine/nonblocking/nonblocking-queue.vala
@@ -115,7 +115,7 @@ public class Geary.Nonblocking.Queue<G> : BaseObject {
}
/**
- * Retrieves the next item from the queue, blocking until available.
+ * Removes and returns the next queued item, blocking until available.
*
* If the queue is paused, this will continue to wait until
* unpaused and an item is ready. If `cancellable` is non-null,
@@ -130,6 +130,22 @@ public class Geary.Nonblocking.Queue<G> : BaseObject {
}
}
+ /**
+ * Returns the next queued item without removal, blocking until available.
+ *
+ * If the queue is paused, this will continue to wait until
+ * unpaused and an item is ready. If `cancellable` is non-null,
+ * when used will cancel this call.
+ */
+ public async G peek(Cancellable? cancellable = null) throws Error {
+ for (;;) {
+ if (queue.size > 0 && !is_paused)
+ return queue.peek();
+
+ yield spinlock.wait_async(cancellable);
+ }
+ }
+
/**
* Removes all items in queue, returning the number of removed items.
*/
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]