mirror of
https://github.com/gnh1201/welsonjs.git
synced 2025-02-06 15:04:58 +00:00
Update pipe-ipc.js
This commit is contained in:
parent
c0dc768588
commit
c3435f7aac
|
@ -85,6 +85,10 @@ function CRC32(str) {
|
|||
return ((crc ^ (-1)) >>> 0).toString(16).padStart(8, '0');
|
||||
}
|
||||
|
||||
function makeProbabilityBit(p) {
|
||||
return !( p > 0.0 ? ( (randomize() / p) > 1.0 ) : true) ? 1 : 0;
|
||||
}
|
||||
|
||||
function createFSO() {
|
||||
return CreateObject("Scripting.FileSystemObject");
|
||||
}
|
||||
|
@ -156,13 +160,18 @@ function PipeIPC() {
|
|||
this.maxSentences = maxSentences;
|
||||
};
|
||||
|
||||
this.waitForRetry = function() {
|
||||
var t = makeProbabilityBit(0.5);
|
||||
if (t > 0) sleep(t);
|
||||
};
|
||||
|
||||
this.connect = function(pipename, callback) {
|
||||
if (pipename == "volatile") {
|
||||
pipename = createUUIDv4().substring(0, 8);
|
||||
}
|
||||
this.path = this.path.replace(":pipename", pipename);
|
||||
//this.openWriter();
|
||||
this.openReader();
|
||||
//this.openReader();
|
||||
//console.info("Opened pipe:", pipename);
|
||||
if (typeof callback === "function") {
|
||||
callback(this, this.reader, this.writer);
|
||||
|
@ -217,6 +226,7 @@ function PipeIPC() {
|
|||
isExistsTmpFile = checkFileExists(this.tmpfile);
|
||||
} catch (e) {
|
||||
isExistsTmpFile = false;
|
||||
this.waitForRetry();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -264,6 +274,7 @@ function PipeIPC() {
|
|||
//console.log(e.message);
|
||||
this.closeWriter();
|
||||
isWritten = false;
|
||||
this.waitForRetry();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -288,10 +299,12 @@ function PipeIPC() {
|
|||
this.closeRecorder();
|
||||
this.commit(this.savefile);
|
||||
isRecorded = true;
|
||||
this.closeRecorder();
|
||||
} catch (e) {
|
||||
//console.log(e.message);
|
||||
this.closeRecorder();
|
||||
isRecorded = false;
|
||||
this.waitForRetry();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -329,6 +342,7 @@ function PipeIPC() {
|
|||
done = true;
|
||||
} catch (e) {
|
||||
done = false;
|
||||
this.waitForRetry();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
@ -350,6 +364,7 @@ function PipeIPC() {
|
|||
} catch (e) {
|
||||
//console.log(e.message);
|
||||
isCommited = false;
|
||||
this.waitForRetry();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -367,7 +382,9 @@ function PipeIPC() {
|
|||
this.closeWriter();
|
||||
isFlushed = true;
|
||||
} catch (e) {
|
||||
this.closeWriter();
|
||||
isFlushed = false;
|
||||
this.waitForRetry();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -391,12 +408,14 @@ function PipeIPC() {
|
|||
|
||||
while (!isRead) {
|
||||
try {
|
||||
this.openReader();
|
||||
text += this._read(this.reader);
|
||||
isRead = true;
|
||||
this.lastReadTime = this.getCurrentTime();
|
||||
this.closeReader();
|
||||
} catch (e) {
|
||||
this.closeReader();
|
||||
this.openReader();
|
||||
this.waitForRetry();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -477,7 +496,7 @@ exports.adSaveCreateNotExist = adSaveCreateNotExist;
|
|||
exports.adSaveCreateOverWrite = adSaveCreateOverWrite;
|
||||
exports.adModeReadWrite = adModeReadWrite;
|
||||
|
||||
exports.VERSIONINFO = "PIPE-based IPC Module (pipe-ipc.js) version 0.1.16";
|
||||
exports.VERSIONINFO = "PIPE-based IPC Module (pipe-ipc.js) version 0.1.17";
|
||||
exports.AUTHOR = "abuse@catswords.net";
|
||||
exports.global = global;
|
||||
exports.require = require;
|
||||
|
|
Loading…
Reference in New Issue
Block a user