summaryrefslogtreecommitdiff
path: root/modules/async/tests/immediate.cpp
blob: 5a59ccd31c23b769c6208ce1e9f0b6b94bc139c8 (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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include <forstio/test/suite.hpp>

#include <forstio/templates.hpp>

#include "../c++/async.hpp"

namespace {
SAW_TEST("Immediate Conveyor"){
	using namespace saw;

	event_loop loop;
	wait_scope wait{loop};

	int val = 5;
	conveyor<int> immediately_done{val};

	int passed = 0;
	auto res = immediately_done.then([&passed](int a) {
		passed = a;
	}).sink();

	wait.poll();

	SAW_EXPECT(passed == val, "Expected a 5 in passed value.");
}

SAW_TEST("Immediate Conveyor Queueing"){
	using namespace saw;

	event_loop loop;
	wait_scope wait{loop};

	int val = 5;
	conveyor<int> immediately_done{val};

	int passed = 0;
	bool has_failed = false;
	auto res = immediately_done.then([&passed](int a) {
		passed = a;
	}).sink([&](auto err){
		has_failed = true;
		return err;
	});

	wait.poll();
	wait.poll();
	wait.poll();
	wait.poll();
	wait.poll();

	SAW_EXPECT(passed == val, "Expected a 5 in passed value.");
	SAW_EXPECT(!has_failed, "No error should occur in queueing");
}
}