File tree Expand file tree Collapse file tree 6 files changed +50
-6
lines changed Expand file tree Collapse file tree 6 files changed +50
-6
lines changed Original file line number Diff line number Diff line change 21
21
- [ run and run_forever] ( headers/basic/run.md )
22
22
- [ detached] ( headers/basic/detached.md )
23
23
- [ spawn] ( headers/basic/spawn.md )
24
+ - [ Waitable] ( headers/basic/waitable.md )
24
25
- [ async/result.hpp] ( headers/result.md )
25
26
- [ async/oneshot.hpp] ( headers/oneshot-event.md )
26
27
- [ async/wait-group.hpp] ( headers/wait-group.md )
Original file line number Diff line number Diff line change @@ -7,13 +7,13 @@ via the IO service.
7
7
## Prototype
8
8
9
9
``` cpp
10
- template <typename IoService>
10
+ template <Waitable IoService>
11
11
void run_forever (IoService ios); // (1)
12
12
13
13
template<typename Sender >
14
14
Sender::value_type run(Sender s); // (2)
15
15
16
- template<typename Sender, typename IoService>
16
+ template<typename Sender, Waitable IoService>
17
17
Sender::value_type run(Sender s, IoService ios); // (3)
18
18
```
19
19
@@ -24,11 +24,13 @@ inline as there's no way to wait for it to complete.
24
24
25
25
### Requirements
26
26
27
- `IoService` is an [IO service](io-service.md), and `Sender` is a sender.
27
+ `IoService` is an [IO service](/io-service.md), and must be a
28
+ [Waitable](./waitable.md), and `Sender` is a sender.
28
29
29
30
### Arguments
30
31
31
- - `IoService` - the IO service to use to wait for completion.
32
+ - `IoService` - the IO service to use to wait for completion. Must fulfill the
33
+ [Waitable](./waitable.md) concept.
32
34
- `Sender` - the sender to start.
33
35
34
36
### Return value
Original file line number Diff line number Diff line change
1
+ # ` concept Waitable `
2
+
3
+ The ` Waitable ` concept holds all the requirements for an [ IO
4
+ service] ( /io-service.md ) . Presently, this is only a ` wait() ` method.
5
+
6
+ ## Prototype
7
+
8
+ ``` cpp
9
+ template <typename T>
10
+ concept Waitable = ...;
11
+ ```
12
+
13
+ ### Requirements
14
+
15
+ ` T ` provides a instance wait method that can be called on a value.
16
+
17
+ ## Examples
18
+
19
+ ``` cpp
20
+ struct io_service {
21
+ /** \pre loop must still be alive * /
22
+ void wait() {
23
+ auto loop = m_loop.lock();
24
+ assert(loop);
25
+ loop->wait();
26
+ }
27
+ private:
28
+ friend struct event;
29
+ io_service(std::weak_ptr<event > e) : m_loop { std::move(e) } {}
30
+ std::weak_ptr<event > m_loop;
31
+ };
32
+ static_assert(async::Waitable<io_service>);
33
+ ```
Original file line number Diff line number Diff line change
1
+ # async/wait-group.hpp
Original file line number Diff line number Diff line change @@ -7,6 +7,8 @@ The IO service must provide one method: `void wait()`. This method is called whe
7
7
there is no more work to do currently. It waits for any event to happen, and wakes
8
8
up the appropriate coroutine/operation which awaited the event.
9
9
10
+ See also: the [ Waitable] ( /headers/basic/waitable.md ) concept.
11
+
10
12
** Note:** ` async::run ` and ` async::run_forever ` (see [ here] ( headers/basic/run.md#prototype ) )
11
13
take the IO service by value, not by reference.
12
14
Original file line number Diff line number Diff line change @@ -309,7 +309,12 @@ struct run_queue {
309
309
// Top-level execution functions.
310
310
// ----------------------------------------------------------------------------
311
311
312
- template <typename IoService>
312
+ template <typename T>
313
+ concept Waitable = requires (T t) {
314
+ t.wait ();
315
+ }
316
+
317
+ template <Waitable IoService>
313
318
void run_forever (IoService ios) {
314
319
while (true ) {
315
320
ios.wait ();
@@ -364,7 +369,7 @@ typename Sender::value_type run(Sender s) {
364
369
platform::panic (" libasync: Operation hasn't completed and we don't know how to wait" );
365
370
}
366
371
367
- template <typename Sender, typename IoService>
372
+ template <typename Sender, Waitable IoService>
368
373
requires std::same_as<typename Sender::value_type, void >
369
374
void run (Sender s, IoService ios) {
370
375
struct state {
You can’t perform that action at this time.
0 commit comments