summaryrefslogtreecommitdiff
path: root/src/test/test.c
blob: 652e0f4b94358d404ea0c55b83c625bdcf3a56cf (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
#include "async.h"
#include <stdio.h>
#include <unistd.h>

static int func2(int a) {
    sleep(a);
    return 2*a;
}

/*
static void func1(int a) {
    printf("func1: %d\n", func2(a));
}

static void func3() {
    printf("func3!\n");
}
*/

int main() {
    async_pool_t* pool = async_pool_create(2);
    async_thunk_id_t id1 = async_submit(pool, func2, 7, true);
    async_thunk_id_t id2 = async_submit(pool, func2, 3, true);
    async_thunk_id_t id3 = async_submit(pool, func2, 1, true);
    async_thunk_id_t id4 = async_submit(pool, func2, 5, true);
    async_pool_join(pool);
    printf("3: %d\n", (int) async_await(pool, id3));
    printf("4: %d\n", (int) async_await(pool, id4));
    printf("1: %d\n", (int) async_await(pool, id1));
    printf("2: %d\n", (int) async_await(pool, id2));
    async_pool_destroy(pool);
    return 0;
}