1
This commit is contained in:
parent
43ee63e993
commit
15ea46ca30
@ -2,8 +2,11 @@
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include <f8/timer.h>
|
||||
|
||||
#include "coroutine.h"
|
||||
#include "comgr.h"
|
||||
#include "app.h"
|
||||
|
||||
void Awaiter::Await(std::shared_ptr<Awaiter> notifyer)
|
||||
{
|
||||
@ -122,3 +125,17 @@ void Coroutine::DoResume()
|
||||
{
|
||||
CoResume();
|
||||
}
|
||||
|
||||
void TimerPromise::DoAwait()
|
||||
{
|
||||
std::shared_ptr<TimerPromise> self = std::static_pointer_cast<TimerPromise>(Awaiter::shared_from_this());
|
||||
f8::Timer::Instance()->SetTimeout
|
||||
(
|
||||
time_,
|
||||
[self] (int event, const a8::Args* args) mutable
|
||||
{
|
||||
if (event == a8::TIMER_EXEC_EVENT) {
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -45,7 +45,7 @@ protected:
|
||||
friend class Coroutine;
|
||||
};
|
||||
|
||||
class Promise : public Awaiter
|
||||
class Promise : public Awaiter, public std::enable_shared_from_this<Promise>
|
||||
{
|
||||
protected:
|
||||
|
||||
@ -53,6 +53,21 @@ protected:
|
||||
|
||||
};
|
||||
|
||||
class TimerPromise : public Promise, public std::enable_shared_from_this<TimerPromise>
|
||||
{
|
||||
public:
|
||||
|
||||
TimerPromise(long long time) { time_ = time; };
|
||||
|
||||
protected:
|
||||
|
||||
virtual void DoAwait() override;
|
||||
|
||||
private:
|
||||
long long time_ = 0;
|
||||
|
||||
};
|
||||
|
||||
class Coroutine : public Awaiter
|
||||
{
|
||||
public:
|
||||
|
Loading…
x
Reference in New Issue
Block a user