Skip to content

Commit 3d501c2

Browse files
committed
Update README
1 parent e942458 commit 3d501c2

File tree

1 file changed

+16
-14
lines changed

1 file changed

+16
-14
lines changed

README.md

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Supported functionality:
1717
* Timer functionality (`sleep`, `tick`)
1818
* File functionality (`read`, `write`, `mkdir`, `unlink`, ...)
1919
* A libcurl integration, allowing e.g. HTTP(S) downloads.
20-
* A libpqxx integration, for easy asynchronous interaction with PostgreSQL databases.
20+
* A libpqxx integration, for asynchronous interaction with PostgreSQL databases.
2121
* A threadpool for synchronous or CPU-bound tasks
2222
* A `SelectSet` for polling multiple promises at once
2323

@@ -29,13 +29,11 @@ underlying coroutine to run.
2929
Where I/O or other activity causes a coroutine to be resumed, the coroutine will typically be run by
3030
the scheduler, which you don't need to care about. Depending on the `RunMode`, pending coroutines
3131
are either run once per event loop turn, or immediately from the libuv callback (`Immediate`). By
32-
default, they are run all at once in every event loop turn (`Deferred`).
32+
default, they are run all at once in every event loop turn (`Deferred`). While you can set the run
33+
mode for I/O events in `uvco::runMain()` (`Deferred` vs. `Immediate`), the externally visible
34+
behavior should be the same, and code will work in both modes. If it doesn't: that's a bug in uvco.
3335

34-
However, as a user you shouldn't have to care about this. While you can set the run mode for
35-
I/O events in `uvco::runMain()` (`Deferred` vs. `Immediate`), the externally visible behavior should
36-
be the same, and code will work in both modes. If it doesn't: that's a bug in uvco.
37-
38-
Some types - like buffers received by sockets - use simple types like strings, which are easy to
36+
Some types - like buffers filled by sockets - use simple types like strings, which are easy to
3937
handle but not super efficient. This may need to be generalized.
4038

4139
## Goal
@@ -44,15 +42,17 @@ Provide ergonomic asynchronous abstractions of all libuv functionality, at satis
4442

4543
## Examples
4644

47-
To run a coroutine, you need to set up an event loop. This is done by calling
48-
`uvco::runMain` with a lambda that returns a `uvco::Promise<T>`. `runMain()` either
49-
returns the resulting value after the event loop has finished, or throws an exception if
50-
a coroutine threw one.
45+
To run a coroutine, you need to set up an event loop. This is done by calling `uvco::runMain` with a
46+
callable taking a single `const Loop&` argument and returns a `uvco::Promise<T>`. `runMain()` either
47+
returns the resulting value after the event loop has finished, or throws an exception if a coroutine
48+
threw one.
5149

5250
A `Promise<T>` is a coroutine promise, and can be awaited. It is the basic unit, and only
5351
access to concurrency; there is no `Task` or such. Awaiting a promise will save the current
5452
execution state, and resume it as soon as the promise is ready. Currently, promises cannot
55-
be cancelled.
53+
be properly cancelled; however, suspended coroutines can be cancelled - although the coroutine
54+
they're waiting on will still run to completion (that's the downside of not having a `Task`
55+
primitive).
5656

5757
When in doubt, refer to the examples in `test/`; they are actively maintained.
5858

@@ -68,9 +68,11 @@ trigger coroutine resumption from the event loop, which is defined in `src/run.c
6868
#include "run.h"
6969
#include "promise/promise.h"
7070

71+
using namespace uvco;
72+
7173
Promise<void> someAsynchronousFunction(const Loop& loop) {
7274
fmt::print("Hello from someAsynchronousFunction\n");
73-
co_await loop.sleep(1000);
75+
co_await sleep(loop, 1000);
7476
fmt::print("Goodbye from someAsynchronousFunction\n");
7577
}
7678

@@ -80,7 +82,7 @@ void run_loop() {
8082
// The `loop` mediates access to the event loop and is used by uvco's types.
8183
// Create a "root" promise by calling a coroutine, e.g. one that
8284
// sets up a server.
83-
uvco::runMain<void>([](const Loop& loop) -> uvco::Promise<void> {
85+
runMain<void>([](const Loop& loop) -> Promise<void> {
8486
co_await someAsynchronousFunction(loop);
8587
});
8688
}

0 commit comments

Comments
 (0)