| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef MOJO_EDK_SYSTEM_ASYNC_WAITER_H_ | 5 #ifndef MOJO_EDK_SYSTEM_ASYNC_WAITER_H_ |
| 6 #define MOJO_EDK_SYSTEM_ASYNC_WAITER_H_ | 6 #define MOJO_EDK_SYSTEM_ASYNC_WAITER_H_ |
| 7 | 7 |
| 8 #include <functional> | 8 #include <functional> |
| 9 | 9 |
| 10 #include "mojo/edk/system/awakable.h" | 10 #include "mojo/edk/system/awakable.h" |
| 11 #include "mojo/public/c/system/result.h" | 11 #include "mojo/public/c/system/result.h" |
| 12 #include "mojo/public/cpp/system/macros.h" | 12 #include "mojo/public/cpp/system/macros.h" |
| 13 | 13 |
| 14 namespace mojo { | 14 namespace mojo { |
| 15 namespace system { | 15 namespace system { |
| 16 | 16 |
| 17 // An |Awakable| implementation that just calls a given callback object. | 17 // An |Awakable| implementation that just calls a given callback object. It |
| 18 // should be used in a non-persistent way (i.e., |Awake()| should be called at |
| 19 // most once by each source, and only for "leading edges"). |
| 18 class AsyncWaiter final : public Awakable { | 20 class AsyncWaiter final : public Awakable { |
| 19 public: | 21 public: |
| 20 using AwakeCallback = std::function<void(MojoResult)>; | 22 using AwakeCallback = std::function<void(MojoResult)>; |
| 21 | 23 |
| 22 // |callback| must satisfy the same contract as |Awakable::Awake()|. | 24 // |callback| must satisfy the same contract as |Awakable::Awake()|. |
| 23 explicit AsyncWaiter(const AwakeCallback& callback); | 25 explicit AsyncWaiter(const AwakeCallback& callback); |
| 24 ~AsyncWaiter() override; | 26 ~AsyncWaiter() override; |
| 25 | 27 |
| 26 private: | 28 private: |
| 27 // |Awakable| implementation: | 29 // |Awakable| implementation: |
| 28 bool Awake(uint64_t context, | 30 void Awake(uint64_t context, |
| 29 AwakeReason reason, | 31 AwakeReason reason, |
| 30 const HandleSignalsState& signals_state) override; | 32 const HandleSignalsState& signals_state) override; |
| 31 | 33 |
| 32 AwakeCallback callback_; | 34 AwakeCallback callback_; |
| 33 | 35 |
| 34 MOJO_DISALLOW_COPY_AND_ASSIGN(AsyncWaiter); | 36 MOJO_DISALLOW_COPY_AND_ASSIGN(AsyncWaiter); |
| 35 }; | 37 }; |
| 36 | 38 |
| 37 } // namespace system | 39 } // namespace system |
| 38 } // namespace mojo | 40 } // namespace mojo |
| 39 | 41 |
| 40 #endif // MOJO_EDK_SYSTEM_ASYNC_WAITER_H_ | 42 #endif // MOJO_EDK_SYSTEM_ASYNC_WAITER_H_ |
| OLD | NEW |