It looks like it synchronously goes from the first EM_ASM to the [ Open and read ] section? Instead, the callback from syncfs will be called asynchronously in the future; that is when it is safe to open and read a file that syncfs loads for you.
- Alon On Thu, Apr 16, 2015 at 7:58 AM, Mike Arnautov <[email protected]> wrote: > I seem to have hit a wall trying to use IDBFS for persistent storage -- > quite possibly due to my abysmal ignorance of emscripten subtleties, so any > advice would be very welcome. > > My C app has a setup routine which, stripped to the essentials, looks like > this: > > char *setup(char *type) > { > if (strcmp(type, "SYNCED") != 0) > { > EM_ASM( > FS.mkdir('/data'); > FS.mount(IDBFS, {}, '/data'); > FS.chdir('/data'); > FS.syncfs(true, function(err) > { > if(err) alert('ERROR! ' + err); > else { ccall (setup, 'SYNCED'); } > }); > ); > #ifdef DELAY > EM_ASM( alert('SETUP proceeding...'); ); > #endif /* DELAY */ > [ Open and read pre-existing data file ] > } > else > { [Do some other stuff ] } > return [a result string pointer]; > } > > As you see, this code allows for the async nature of the FS.synfs() call, > but the program fails to find the pre-existing file unless a delay is > introduced by, e.g., activating the alert call in the above. With such a > delay all works as I would expect. It very much looks like the FS.sync > callback is triggered immediately, without waiting for the actual > synchronisation to take place. > > Am I missing something? If so, what? Any suggestions gratefully received. > > -- > 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.
