1. This website uses cookies to improve service and provide a tailored user experience. By using this site, you agree to this use. See our Cookie Policy.
    Dismiss Notice

Trying to make an AJAX a promise in order to force the app to wait

Discussion in 'Programming' started by kunte, Jan 19, 2019.

  1. kunte

    kunte Registered Member

    Joined:
    Nov 13, 2018
    Messages:
    83
    Likes Received:
    38
    Gender:
    Male
    I'm trying to use an AJAX in an application using puppeteer.js. In puppeteer everything returns a promise so you can effectively use the await keyword before most actions to force it to wait. This is kind of crucial since I need certain things done in chronological order.

    However, let's say I have some vendor code that performs an AJAX request deeply nested inside a function. I want to somehow use that function and force the app to wait for a response before continuing.

    I basically want to use await keyword but with a custom function. I almost want the function to inherit from promise because or else I can't use it?
     
  2. sockpuppet

    sockpuppet Junior Member

    Joined:
    Nov 7, 2011
    Messages:
    164
    Likes Received:
    154
    your custom function only needs to return a new promise
    but to make it work you need to know when the request is done, a callback or some event?
     
  3. moutman

    moutman Newbie

    Joined:
    May 12, 2019
    Messages:
    1
    Likes Received:
    0
    you can use waitForFunction