Skip to content

Commit

Permalink
Merge pull request #10 from couchbaselabs/then
Browse files Browse the repository at this point in the history
Implemented Future.then(...) for chaining without coroutines
  • Loading branch information
snej authored Sep 13, 2023
2 parents d87e665 + 2141ad4 commit dd9210d
Show file tree
Hide file tree
Showing 17 changed files with 325 additions and 217 deletions.
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

0 comments on commit dd9210d

Please sign in to comment.