1
0
mirror of https://github.com/tearshark/librf.git synced 2024-10-02 00:00:11 +08:00
librf/tutorial/test_async_suspend_always.cpp

94 lines
2.4 KiB
C++
Raw Normal View History

2017-09-24 14:01:30 +08:00

#include <chrono>
#include <iostream>
#include <string>
#include <conio.h>
#include <thread>
#include "librf.h"
using namespace resumef;
future_t<> test_loop_sleep(size_t _N, const char * ch)
2017-09-24 14:01:30 +08:00
{
using namespace std::chrono;
for (size_t i = 0; i < _N; ++i)
{
co_await resumef::sleep_for(100ms);
std::cout << ch;
2017-09-24 14:01:30 +08:00
}
std::cout << std::endl;
}
future_t<> test_recursive_await()
2017-09-24 14:01:30 +08:00
{
std::cout << "A:---1" << std::endl;
co_await test_loop_sleep(5, "=");
2017-09-24 14:01:30 +08:00
std::cout << "A:---2" << std::endl;
co_await test_loop_sleep(6, "=");
2017-09-24 14:01:30 +08:00
std::cout << "A:---3" << std::endl;
co_await test_loop_sleep(7, "=");
2017-09-24 14:01:30 +08:00
std::cout << "A:---4" << std::endl;
2017-09-24 14:01:30 +08:00
}
future_t<> test_recursive_go()
2017-09-24 14:01:30 +08:00
{
std::cout << "B:---1" << std::endl;
co_await test_loop_sleep(3, "+");
2017-09-24 14:01:30 +08:00
std::cout << "B:---2" << std::endl;
go test_loop_sleep(8, "*");
2017-09-24 14:01:30 +08:00
std::cout << "B:---3" << std::endl;
co_await test_loop_sleep(4, "+");
2017-09-24 14:01:30 +08:00
std::cout << "B:---4" << std::endl;
2017-09-24 14:01:30 +08:00
}
void resumable_main_suspend_always()
{
go test_recursive_await();
go test_recursive_go();
2017-10-01 10:33:08 +08:00
this_scheduler()->run_until_notask();
2017-09-24 14:01:30 +08:00
}
/*
resume from 0000016B8477CE00 on thread 7752
resume from 0000016B847726C0 on thread 7752
.resume from 0000016B847726C0 on thread 7752
.resume from 0000016B847726C0 on thread 7752
.resume from 0000016B847726C0 on thread 7752
.resume from 0000016B847726C0 on thread 7752
.
resume from 0000016B8477CE00 on thread 7752
resume from 0000016B847726C0 on thread 7752
.resume from 0000016B847726C0 on thread 7752
.resume from 0000016B847726C0 on thread 7752
.resume from 0000016B847726C0 on thread 7752
.resume from 0000016B847726C0 on thread 7752
.resume from 0000016B847726C0 on thread 7752
.
resume from 0000016B8477CE00 on thread 7752
resume from 0000016B847726C0 on thread 7752
.resume from 0000016B847726C0 on thread 7752
.resume from 0000016B847726C0 on thread 7752
.resume from 0000016B847726C0 on thread 7752
.resume from 0000016B847726C0 on thread 7752
.resume from 0000016B847726C0 on thread 7752
.resume from 0000016B847726C0 on thread 7752
.
resume from 0000016B8477CE00 on thread 7752
test_recursive_await -> 0000016B8477CE00
test_loop_sleep<5> -> 0000016B847726C0
test_loop_sleep<6> -> 0000016B847726C0
test_loop_sleep<7> -> 0000016B847726C0
*/