folly::Future integration with Python
authorAndrii Grynenko <andrii@fb.com>
Wed, 4 May 2016 21:32:54 +0000 (14:32 -0700)
committerFacebook Github Bot 6 <facebook-github-bot-6-bot@fb.com>
Wed, 4 May 2016 21:35:24 +0000 (14:35 -0700)
Summary:
This diff implements two functions which can be used to bridge C++ asynchronous APIs with Python.
1. getExecutor(event_loop) allows extracting a folly::Executor-compatible object from Python event_loop.
2. wrapFuture wraps any folly::Future object in a Python Future object.

Reviewed By: ambv

Differential Revision: D2878731

fb-gh-sync-id: 83628b6b24d6039999f88c5de441e41064b2417e
fbshipit-source-id: 83628b6b24d6039999f88c5de441e41064b2417e

folly/io/async/NotificationQueue.h

index 4714ef8d8c6e85c2b9aa552cba7de215c3bf803e..acbd3c37c3ae118e12c1b843c731db40e6bbc71e 100644 (file)
@@ -213,6 +213,24 @@ class NotificationQueue {
     bool active_{false};
   };
 
     bool active_{false};
   };
 
+  class SimpleConsumer {
+   public:
+    explicit SimpleConsumer(NotificationQueue& queue) : queue_(queue) {
+      ++queue_.numConsumers_;
+    }
+
+    ~SimpleConsumer() {
+      --queue_.numConsumers_;
+    }
+
+    int getFd() const {
+      return queue_.eventfd_ >= 0 ? queue_.eventfd_ : queue_.pipeFds_[0];
+    }
+
+   private:
+    NotificationQueue& queue_;
+  };
+
   enum class FdType {
     PIPE,
 #ifdef FOLLY_HAVE_EVENTFD
   enum class FdType {
     PIPE,
 #ifdef FOLLY_HAVE_EVENTFD