I would like to have a function that makes an async call, and returns 
control to the browser during the call, then resumes once the async call is 
complete. However, I would like this to appear to the calling code to be a 
synchronous call. So for instance, I could do something like this:

struct FileInfo
{
    void* buffer;
    unsigned size;
};

FileInfo loadUrl(const char* url)
{
    FileInfo info;
    emscripten_async_wget2_data(url, "GET", "", &info, false, onload, 
onerror, onprogress);
    emscripten_pause(); // Blocks until emscripten_resume() is called
    return info;
}

void onerror(void* ptr, int code, const char* desc)
{
    // Handle not found, etc.
}

void onprogress(void* ptr, int loaded, int total)
{
    // Update progress bar
}

void onload(void* ptr, void* buffer, unsigned size)
{
    static_cast<FileInfo*>(ptr)->buffer = buffer;
    static_cast<FileInfo*>(ptr)->size = size;

    emscripten_resume(); // Now loadUrl resumes and returns FileInfo.
}

Is there any way to do this?

-- 
You received this message because you are subscribed to the Google Groups 
"emscripten-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to