gnh1201 / welsonjs

WelsonJS - Build a Windows app on the Windows built-in JavaScript engine

Home Page:https://catswords.social/@catswords_oss

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[lib/pipe-ipc] Improving concurrencies in a multiprocessing

gnh1201 opened this issue · comments

Summary

Resolution of issues encountered when requiring concurrencies in a multiprocessing environment

Related to IPC(Inter-Process Communication)

  • Adding PIPE-based IPC (lib/pipe-ipc)
  • Applying PIPE-based IPC to SHELL interface (lib/shell)
  • Applying PIPE-based IPC to FILE interface (lib/file)
  • Applying PIPE-based IPC to HTTP interface (lib/http) cbac701 2912ca8
  • Ensure complete compatibility with previous versions

Related to processes

  • Support a async keyword -> make a AsyncFunction class (lib/std)

Related issues

Summary of Actual User Case

After applying the improvements, when using the writeFile and readFile function and providing absolutely nothing, not even a blank (''), it would simply wait indefinitely without performing any task.

  • This behavior was not originally allowed, and the issue occurred after the improvement.
  • However, since it is currently being used in this way, a warning message is now displayed, and the intended operation (file creation) has been modified to proceed as intended.

Code snippets

lib/file.js

function writeFile(FN, content, charset) {
    if (typeof content === "undefined") {
        console.warn("CONTENT has not been passed. Force to empty string.");
        content = '';
    }
    if (typeof charset === "undefined") {
        console.warn("CHARSET has not been passed. Force to UTF-8.");
        charset = PipeIPC.CdoUTF_8;
    }

    var pipe = PipeIPC.connect("volatile");
    pipe.setCharset(charset);
    pipe.startRecorder(FN, PipeIPC.ForWriting);
    pipe.write(content);
    pipe.destroy();
    return true;
}
function readFile(FN, charset) {
    if (typeof charset === "undefined") {
        console.warn("CHARSET has not been passed. Force to UTF-8.");
        charset = PipeIPC.CdoUTF_8;
    }

    var text =  ''; 
    var pipe = PipeIPC.connect("volatile");
    pipe.setCharset(charset);
    pipe.loadFromFile(FN, charset);
    text += pipe.read();
    pipe.destroy();

    return text;
}

In a caller

var filename = "helloworld.txt";
writeFile(filename);   // not correctly but allowed
//writeFile(filename, "helloworld", "utf-8");   // correctly

var text = readFile(filename);   // not correctly but allowed
//readFile(filename, "utf-8");   // correctly
console.log(text);