Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2014
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.58 KB | None | 0 0
  1. class InputArchive {
  2.  
  3. ...
  4.  
  5. template <typename T>
  6. void process ( T && t ) {
  7.     emscripten_yield();
  8.     // deserialize ...
  9. }
  10.  
  11. template <typename T>
  12. emscripten_coroutine async( T && t ) {
  13.     // create type-erasure proxy that holds T
  14.     return emscripten_coroutine_create( &coro_func, &proxy );
  15. }
  16.  
  17. static void coro_func( void * arg ) {
  18.     // cast arg to proxy
  19.     proxy.process(); // proxy holds T argument, dispatch it to InputArchive::process
  20. }
  21.  
  22. };
  23.  
  24.  
  25. void deserialize() {
  26.     Document doc;
  27.     auto coroutine = archive.async( doc );
  28.  
  29.     while( emscripten_coroutine_next( coroutine ) != 0 ) {}
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement