Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented Future.then(...) for chaining without coroutines #10

Merged
merged 5 commits into from
Sep 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 16 additions & 19 deletions include/Actor.hh
Original file line number Diff line number Diff line change
Expand Up @@ -106,26 +106,23 @@ namespace crouton {

explicit ActorMethodImpl(crouton::Actor const* actor, ...) :ActorMethodImpl(*actor) { }

struct suspendInitial : public CORO_NS::suspend_always {
ActorMethodImpl* self;
bool await_ready() const noexcept {
return self->_actor->startNew(self->handle());
}
void await_suspend(coro_handle cur) {
lifecycle::suspendInitial(cur);
}
};

struct suspendFinal : public Finisher {
ActorMethodImpl* self;
coro_handle await_suspend(coro_handle h) noexcept {
self->_actor->finished(h);
return Finisher::await_suspend(h);
}
};
auto initial_suspend() {
struct suspendInitial : public CORO_NS::suspend_always {
ActorMethodImpl* self;
bool await_ready() const noexcept {
return self->_actor->startNew(self->handle());
}
void await_suspend(coro_handle cur) {
lifecycle::suspendInitial(cur);
}
};
return suspendInitial{{},this};
}

suspendInitial initial_suspend() { return suspendInitial{{},this}; }
suspendFinal final_suspend() noexcept { return suspendFinal{{},this}; }
auto final_suspend() noexcept {
_actor->finished(this->handle());
return FutureImpl<T>::final_suspend();
}

private:
ActorMethodImpl() = delete; // I need to know the identity of the Actor owning the coro
Expand Down
Loading