summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorNao Pross <naopross@thearcway.org>2019-01-23 20:33:33 +0100
committerNao Pross <naopross@thearcway.org>2019-01-23 20:33:33 +0100
commitd0f35bf97063d1d786713f373e4753bed56d4f0b (patch)
tree19dc0f18ca966424b286b1cf1e4dd686f60eaa64 /test
parentMerge branch 'raii-task' (diff)
downloadflatland-d0f35bf97063d1d786713f373e4753bed56d4f0b.tar.gz
flatland-d0f35bf97063d1d786713f373e4753bed56d4f0b.zip
Update job interface to allow safe ownership delegation
Diffstat (limited to 'test')
-rw-r--r--test/task_test.cpp29
1 files changed, 14 insertions, 15 deletions
diff --git a/test/task_test.cpp b/test/task_test.cpp
index 76fb3b7..04bb23d 100644
--- a/test/task_test.cpp
+++ b/test/task_test.cpp
@@ -6,21 +6,19 @@
using namespace flat::core;
// test class
-struct message {
-
- message(job& m_job, bool date)
- {
- if (date)
- mytask = m_job.make_task(std::bind(&message::print_date, *this));
- else
- mytask = m_job.make_task(std::bind(&message::print_motd, *this));
- }
-
- std::shared_ptr<task> mytask;
+class message {
+private:
+ task::ptr mytask;
std::string motd = "today we have no motd!";
std::string date = "1 Jan 1970";
+public:
+ message(job& job) {
+ // add an example job
+ mytask = job.delegate_task(&message::print_motd, *this);
+ }
+
void print_date() {
std::cout << date << std::endl;
}
@@ -49,11 +47,11 @@ int main(int argc, char *argv[]) {
job f_job;
// test a function
- auto hello_fn_task = f_job.make_task(hello);
+ auto hello_fn_task = f_job.delegate_task(hello);
// test a function ad make the pointer go out of scope
{
- auto ciao_fn_task = f_job.make_task(ciao);
+ auto ciao_fn_task = f_job.delegate_task(ciao);
}
f_job();
@@ -61,14 +59,15 @@ int main(int argc, char *argv[]) {
std::cout << std::endl;
std::cout << "Testing methods" << std::endl;
std::cout << "should print once: today we have no motd!" << std::endl;
+
job m_job;
// test a method
- message m(m_job, false);
+ message m(m_job);
// test a method of an object that goes out of scope
{
- message out(m_job, true);
+ message out(m_job);
}
// invoke tasks