locked
Convert callback to Async Operation

    Question

  • Hi all,

    I am wondering how to wrap old callback style API into Async operation.

    FooAsync(); // call async API

    ....

    FooCallback(Result); // call back later

    Then I want to convert it into

    IAsyncOperation<TResult> MyClass::FooOperationAsync()

    {

    FooAsync();

    // how to wait for callback and return the result?

    }

    Thanks,


    rob qqq

    Tuesday, July 24, 2012 4:35 PM

All replies

  • IAsyncOperation<TResult> MyClass::FooOperationAsync()

    { return create_async([this]() -> TResult { auto func = FooAsync().wait(); return func->get(); }); }

    Something like this ?


    Tuesday, July 24, 2012 4:48 PM
  • FooAsync is old style API, need to wait for callback.  Can't call FooAsync.wait.

    rob qqq

    Tuesday, July 24, 2012 5:31 PM
  • Do you have an aceess to the old API? Can you rewrite it?

    Tuesday, July 24, 2012 7:46 PM