Hi,
Is it possible to write contents to a file at an indefinite time from 
javascript and read those contents in C code after some amount of time and 
continue this process?

For example, if I write some content from javascript to a shared file at a 
time "t" and want to read that contents in C code at "t+1" time and clear 
those contents from the shared file, and again the javascript code will 
write the contents at "t+2" time and want to read that contents in C code 
at "t+3" time.

Means will the compiled C code (emscripten web assembly)  and our own 
Javascript code can run asynchronously? 

*Javascript Code:*

Module.noInitialRun = true;

Module.onRuntimeInitialized = ()=>
{
    console.log("Initialized");

    const stream = Module.FS.open('./events.txt', 'a+');

    window.addEventListener
    (
        'keyup',
        (ev) =>
        {
            if(ev.key === 'p')
            {
                console.log("Writing");
                const output = 'p';

                const enc = new TextEncoder();
                enc.encode(output);

                const data = enc.encode(output);

                Module.FS.write(stream, data, 0, data.length);
            }
        }
    );

    Module.callMain();
}

*C Code:*

#include <stdio.h>
#include <string.h>

int main()
{
    FILE* ptr;
    char str[50];

    ptr = fopen("./events.txt", "r");

    if (NULL == ptr)
    {
        printf("Unable to open events file\n");
        return -1;
    }

    printf("File contents : \n");

    while (fgets(str, 50, ptr) != NULL)
    {
            printf("%s\n", str);
    }

    // Perform some operations here
    // And again execute the above reading code after some time
    
    return 0;
}

-- 
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].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/emscripten-discuss/f0a1a6ae-7c2a-4a97-9124-b5025dcaedd3n%40googlegroups.com.

Reply via email to