Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(605)

Unified Diff: components/scheduler/promises/single_thread_promise_executor.cc

Issue 1401553002: NOT INTENDED FOR LANDING: A promises demo (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Support for rejectatble promises! Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: components/scheduler/promises/single_thread_promise_executor.cc
diff --git a/components/scheduler/promises/single_thread_promise_executor.cc b/components/scheduler/promises/single_thread_promise_executor.cc
new file mode 100644
index 0000000000000000000000000000000000000000..be36812c3d52c9a0a8cd72e5ae98029541e29074
--- /dev/null
+++ b/components/scheduler/promises/single_thread_promise_executor.cc
@@ -0,0 +1,49 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "components/scheduler/promises/single_thread_promise_executor.h"
+
+#include "base/bind.h"
+
+namespace promise {
+namespace internal {
+
+SingleThreadPromiseExecutor::SingleThreadPromiseExecutor(
+ const scoped_refptr<base::SingleThreadTaskRunner>& task_runner)
+ : task_runner_(task_runner) {}
+
+SingleThreadPromiseExecutor::~SingleThreadPromiseExecutor() {}
+
+void SingleThreadPromiseExecutor::StartResolveInternal(PromiseBase* promise) {
+ PromiseExecutor::StartResolveInternal(promise);
+ DispatchResolveImpl();
+}
+
+void SingleThreadPromiseExecutor::ResolveImpl() {
+ PromiseBase* ready_promise = GetNextReadyPromise();
+ if (!ready_promise)
+ return;
+ ResolvePromise(ready_promise);
+}
+
+void SingleThreadPromiseExecutor::DispatchResolveImpl() {
+ task_runner_->PostTask(FROM_HERE,
+ base::Bind(&SingleThreadPromiseExecutor::ResolveImpl,
+ base::Unretained(this)));
+}
+
+bool SingleThreadPromiseExecutor::OnPromiseResolved(PromiseBase* promise) {
+ if (PromiseExecutor::OnPromiseResolved(promise))
+ DispatchResolveImpl();
+ return false;
+}
+
+bool SingleThreadPromiseExecutor::OnPromiseRejected(PromiseBase* promise) {
+ if (PromiseExecutor::OnPromiseRejected(promise))
+ DispatchResolveImpl();
+ return false;
+}
+
+} // namespace internal
+} // namespace promise

Powered by Google App Engine
This is Rietveld 408576698