Giter Club home page Giter Club logo

Comments (3)

ashleydavis avatar ashleydavis commented on July 17, 2024

Does the 3rd party API give you some sort of callback?

from c-sharp-promise.

theslyone avatar theslyone commented on July 17, 2024

@ashleydavis Wonderful library but I am also caught up in this same situation. Third party API performs some data manipulation and returns an updated response or fails with reasons where required. How does one wait for the then/done/catch callbacks before dispatching an IHttpActionResult response to the calling client?

Thanks

from c-sharp-promise.

RoryDungan avatar RoryDungan commented on July 17, 2024

Old question I know but I figured I should write a response in case anyone else comes across this. It all boils down to how the 3rd party API you're using works, so there is no single solution that will always work without seeing more info.

It depends how the 3rd party API you're

If the API gives you a way to pass a function called when the request is completed, you can create a new Promise<T>() when you first send the request and then call .Resolve(data) on it once you have a result.

IPromise<string> HttpGet(string url)
{
    var promise = new Promise<string>();
    ThirdPartyAPI.Get(url, data => promise.Resolve(data));
    return promise;
}

Similarly, if there is an event triggered when the request completes you can connect that to a function that resolves your promise.

If you want to convert an async/await API to use Promises you should be able to use similar code but call ContinueWith on the async task and resolve your new promise inside the ContinueWith callback. I haven't tested this method though, since async/await already has most of the functionality of Promises built-in anyway.

from c-sharp-promise.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.