Let Future::then call callbacks outside of the catch handler
[folly.git] / folly / futures / QueuedImmediateExecutor.cpp
index f31d1d003f10adde912fedcadf03ca9def336acd..1d2aeea75bb3e0c9517024ff1888dd317742ce38 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2014 Facebook, Inc.
+ * Copyright 2016 Facebook, Inc.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
 
 namespace folly {
 
-void QueuedImmediateExecutor::add(Func callback) {
-  thread_local std::queue<Func> q;
+void QueuedImmediateExecutor::addStatic(Func callback) {
+  static folly::ThreadLocal<std::queue<Func>> q_;
 
-  if (q.empty()) {
-    q.push(std::move(callback));
-    while (!q.empty()) {
-      q.front()();
-      q.pop();
+  if (q_->empty()) {
+    q_->push(std::move(callback));
+    while (!q_->empty()) {
+      q_->front()();
+      q_->pop();
     }
   } else {
-    q.push(callback);
+    q_->push(std::move(callback));
   }
 }