Hi,
Some time passed, and I now had a chance to get back to it.
I started to implement the asio based EventPort and AsyncIOStream; But - for some odd reason - I can't manage to make the Promises to be fulfilled (e.g. their lambdas are never called). Any idea? Note that I see that the 'asio' part is working, and calling the kj eventloop run.
Relevant code snippets (attached only the relevant parts for clarity)
void asio_event_port::setRunnable(bool runnable)
{
this->runnable = runnable;
{
if (this->runnable && event_loop){
// NOTE - I see that this printf is printed, and event_loop->run (kj::event_loop) is indeed called. Note that in the thread scope I've created a WaitScope which receives the eventloop in the c'tor, before starting all of the below
printf("Calling event loop run\n");
event_loop->run();
}
});
}
kj::Promise<void> asio_kj_io_stream::connect(const std::string& host, const std::string& port)
{
ip::tcp::resolver resolver(io_service);
auto server_it = resolver.resolve({ host, port });
auto paf = newPromiseAndFulfiller<void>();
connectFulfiller = std::move(paf.fulfiller);
asio::async_connect(asio_socket, server_it, [this](std::error_code , ip::tcp::resolver::iterator)
{
printf("Async connect lambda called\n");
KJ_IF_MAYBE(f, this->connectFulfiller){
printf("About to fulfill!\n"); // NOTE - I see that this printf is printed
f->get()->fulfill();
}
this->connectFulfiller = nullptr;
});
return kj::mv(paf.promise);
}
// Connect promise is of kj::ForkedPromise<void> type
kj::Promise<void>* myPromise = new kj::Promise<void> (connectPromise.addBranch().then([]()
{
printf("Connect finished!\n"); // Flow will never reach this point
}));