It can capture its environment, so you can put the second half of the function in a lambda, and call the lambda later on when you want to, in response to something.
- Alon On Sun, Mar 16, 2014 at 7:12 PM, Joel Croteau <[email protected]> wrote: > I can understand using Javascript generators, but how would c++ lambdas > help? > On Mar 16, 2014 3:47 PM, "Alon Zakai" <[email protected]> wrote: > >> Currently not. It would require a very different code generation approach >> than we currently have. >> >> In theory something similar could be done using generators, in very >> recent versions of firefox and chrome. But even with the help of >> generators, this is not easy to do, and it is not clear how it would affect >> performance - likely very adversely. >> >> One similar thing you can do is manage your own code using c++11 lambdas. >> You could write a little system that continues to run the current function >> once a callback triggers that. >> >> - Alon >> >> >> >> On Sun, Mar 16, 2014 at 1:43 AM, Joel Croteau <[email protected]> wrote: >> >>> 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. >>> >> >> -- >> You received this message because you are subscribed to a topic in the >> Google Groups "emscripten-discuss" group. >> To unsubscribe from this topic, visit >> https://groups.google.com/d/topic/emscripten-discuss/Op5ifeMjauA/unsubscribe >> . >> To unsubscribe from this group and all its topics, send an email to >> [email protected]. >> >> For more options, visit https://groups.google.com/d/optout. >> > -- > 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. > -- 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.
