Skip to content

Commit

Permalink
[ doc ] add some explanation to Async examples
Browse files Browse the repository at this point in the history
  • Loading branch information
stefan-hoeck committed Jan 12, 2024
1 parent cd4bcc7 commit 704e030
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion docs/src/Docs/UV/Async.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,14 @@ namely the idler that is still running.

## Streaming a File

In this example we stream the content of one file to another.
However, we provide three possibilities how the computation might
stop: `SIGINT` is received, a ten seconds timeout occurs, or the
input stream is exhausted.

This shows, how we can conveniently set up a race of a
heterogeneous list of asynchronous computations.

```idris
parameters {auto l : UVLoop}
fileStreamExample : DocIO ()
Expand All @@ -127,6 +135,11 @@ main = runDoc fileStreamExample

## An echo Server

In this last example, we again set up a simple echo server.
This time, however, the server gracefully closes all client
connections before shutting down (which happens, when
`SIGINT` is received).

```idris
parameters {auto l : UVLoop}
onConnection : AllocCB -> Ptr Stream -> DocIO (Maybe ())
Expand All @@ -135,7 +148,7 @@ parameters {auto l : UVLoop}
client <- acceptTcp server
_ <- streamReadWrite ac client $ \case
Done => pure (Just ())
Data val => bytesOut val >> write client val $> Nothing
Data val => write client val $> Nothing
Err x => throw x
pure Nothing
Expand Down

0 comments on commit 704e030

Please sign in to comment.