mirror of
https://github.com/gnh1201/welsonjs.git
synced 2025-05-14 05:31:03 +00:00
Update pipe-ipc.js
This commit is contained in:
parent
c3cec2bba7
commit
590dde45c1
|
@ -27,7 +27,7 @@ function PipeIPC() {
|
||||||
|
|
||||||
this.createWriter = function() {
|
this.createWriter = function() {
|
||||||
//this.writer = CreateObject("Scripting.FileSystemObject").CreateTextFile(this.path, true, true);
|
//this.writer = CreateObject("Scripting.FileSystemObject").CreateTextFile(this.path, true, true);
|
||||||
this.writer = CreateObject("Scripting.FileSystemObject").OpenTextFile(this.path, ForWriting, true, TristateTrue);
|
this.writer = CreateObject("Scripting.FileSystemObject").OpenTextFile(this.path, ForAppending, true, TristateTrue);
|
||||||
};
|
};
|
||||||
|
|
||||||
this.closeWriter = function() {
|
this.closeWriter = function() {
|
||||||
|
@ -46,6 +46,7 @@ function PipeIPC() {
|
||||||
|
|
||||||
this._write = function(message) {
|
this._write = function(message) {
|
||||||
this.writer.Write(message);
|
this.writer.Write(message);
|
||||||
|
this.writer.Write("\r\n");
|
||||||
};
|
};
|
||||||
|
|
||||||
this.write = function(message) {
|
this.write = function(message) {
|
||||||
|
@ -55,7 +56,6 @@ function PipeIPC() {
|
||||||
try {
|
try {
|
||||||
this.createWriter();
|
this.createWriter();
|
||||||
this._write(message);
|
this._write(message);
|
||||||
sleep(1);
|
|
||||||
this.writer.Close();
|
this.writer.Close();
|
||||||
isWritten = true;
|
isWritten = true;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
@ -65,16 +65,16 @@ function PipeIPC() {
|
||||||
};
|
};
|
||||||
|
|
||||||
this._read = function() {
|
this._read = function() {
|
||||||
return this.reader.ReadAll();
|
return this.reader.ReadAll().split(/\r?\n/);
|
||||||
};
|
};
|
||||||
|
|
||||||
this.read = function() {
|
this.read = function() {
|
||||||
var isRead = false;
|
var isRead = false;
|
||||||
var text = "";
|
var messages = [];
|
||||||
|
|
||||||
while (!isRead) {
|
while (!isRead) {
|
||||||
try {
|
try {
|
||||||
text = this._read();
|
messages = this._read();
|
||||||
isRead = true;
|
isRead = true;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
this.closeReader();
|
this.closeReader();
|
||||||
|
@ -82,17 +82,11 @@ function PipeIPC() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return text;
|
return messages;
|
||||||
};
|
};
|
||||||
|
|
||||||
this.readContinuously = function(callback) {
|
this.readText = function() {
|
||||||
var isNext = true;
|
return this.read().join(' ');
|
||||||
|
|
||||||
if (typeof callback === "function") {
|
|
||||||
while (isNext) {
|
|
||||||
isNext = callback(this, this.read()) || true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
this.close = function() {
|
this.close = function() {
|
||||||
|
@ -105,7 +99,7 @@ exports.create = function() {
|
||||||
return new PipeIPC();
|
return new PipeIPC();
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.VERSIONINFO = "PIPE-based IPC Module (pipe-ipc.js) version 0.1";
|
exports.VERSIONINFO = "PIPE-based IPC Module (pipe-ipc.js) version 0.1.1";
|
||||||
exports.AUTHOR = "Nathan Catswords <catswords@protonmail.com>";
|
exports.AUTHOR = "Nathan Catswords <catswords@protonmail.com>";
|
||||||
exports.global = global;
|
exports.global = global;
|
||||||
exports.require = require;
|
exports.require = require;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user