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

how to adapt to callback style API #368

Open
microcai opened this issue Jan 31, 2024 · 3 comments
Open

how to adapt to callback style API #368

microcai opened this issue Jan 31, 2024 · 3 comments

Comments

@microcai
Copy link

the referenced document says to use

async_xxx(param, callbackhandler)

to

co_await async_xxx(param);

but, that kind of refactoring only works with asio.

we have some old lib that accepts callbacks. now I want to call that old lib function and "co_await" for the callback to be invoked.

hint: I warpped the Executor for the old lib, so the old lib and async_simple runs in the same Executor. I need a way to convert
"lazy<>" to some old style callbacks. and let that callback to resume the calling lazy<>

@ChuanqiXu9
Copy link
Collaborator

but, that kind of refactoring only works with asio.

This is not true. At least not "only".

we have some old lib that accepts callbacks. now I want to call that old lib function and "co_await" for the callback to be invoked.

I didn't understand where the blocker it. Could you explain your question in detail?

@chloro-pn
Copy link
Collaborator

You need to implement awaiter for your asynchronous operation, refer to this demo and coroutine reference

@RainMark
Copy link
Collaborator

RainMark commented Feb 1, 2024

And we can use Future/Promise, call promise setValue in callback, and co_await future in Lazy

refer to https://github.com/alibaba/async_simple/blob/main/async_simple/coro/test/FutureAwaiterTest.cpp

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants