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

Side by Side 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "components/scheduler/promises/single_thread_promise_executor.h"
6
7 #include "base/bind.h"
8
9 namespace promise {
10 namespace internal {
11
12 SingleThreadPromiseExecutor::SingleThreadPromiseExecutor(
13 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner)
14 : task_runner_(task_runner) {}
15
16 SingleThreadPromiseExecutor::~SingleThreadPromiseExecutor() {}
17
18 void SingleThreadPromiseExecutor::StartResolveInternal(PromiseBase* promise) {
19 PromiseExecutor::StartResolveInternal(promise);
20 DispatchResolveImpl();
21 }
22
23 void SingleThreadPromiseExecutor::ResolveImpl() {
24 PromiseBase* ready_promise = GetNextReadyPromise();
25 if (!ready_promise)
26 return;
27 ResolvePromise(ready_promise);
28 }
29
30 void SingleThreadPromiseExecutor::DispatchResolveImpl() {
31 task_runner_->PostTask(FROM_HERE,
32 base::Bind(&SingleThreadPromiseExecutor::ResolveImpl,
33 base::Unretained(this)));
34 }
35
36 bool SingleThreadPromiseExecutor::OnPromiseResolved(PromiseBase* promise) {
37 if (PromiseExecutor::OnPromiseResolved(promise))
38 DispatchResolveImpl();
39 return false;
40 }
41
42 bool SingleThreadPromiseExecutor::OnPromiseRejected(PromiseBase* promise) {
43 if (PromiseExecutor::OnPromiseRejected(promise))
44 DispatchResolveImpl();
45 return false;
46 }
47
48 } // namespace internal
49 } // namespace promise
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698