aboutsummaryrefslogtreecommitdiffhomepage
path: root/notes/async.txt
blob: 11673d0d2d2f36c66607f08ddc26f33cbf3f936c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39



async-after / async-then (decide which keywords to use):

    async {
        # Executed in parallel
        File.open("/etc/myserver/config.cfg").contents_to_string(@cfg.main_cfg)
        File.list("/etc/myserver/config.d/*.conf").add_to_list(@cfg.dir_cfg,
            lambda (File f, Slot<String> entry) -> f.open().contents_to_slot(entry)
    } after {
        server.tls_sock = .new(.listen_local(80, ServerState))
    } after {
        log.info("Server started")
    }
    # The code above is asynchronous, so do_stuff() may be reached before the code above has finished
    do_stuff()


Or:

    async {
        async {
            File.open("/etc/myserver/config.cfg")
        } after {
            ... contents to string ...
        }
        async for Entry e in File.list("/etc/myserver/config.d/*.conf") {
            ...
        }
        ...


Parallel vs async:

- async does not wait for completion
- parallel does (FIXME skip "parallel"?)
    ... which means it is these have different "color" :/
    ... also, it is only parallel if the EventPool is processed by multiple threads