зеркало из https://github.com/mozilla/pluotsorbet.git
Merge pull request #1190 from mykmelez/optimize-dumb-pipe
optimize dumb pipe
This commit is contained in:
Коммит
9c1c0bb2dd
|
@ -53,6 +53,10 @@ var DumbPipe = {
|
|||
return;
|
||||
}
|
||||
|
||||
window.setZeroTimeout(this.handlePipeEvent.bind(this, event));
|
||||
},
|
||||
|
||||
handlePipeEvent: function(event) {
|
||||
if (event.detail.promptType == "custom-prompt") {
|
||||
console.warn("unresponsive script warning; figure out how to handle");
|
||||
return;
|
||||
|
|
20
libs/pipe.js
20
libs/pipe.js
|
@ -45,11 +45,8 @@ var DumbPipe = {
|
|||
sendQueue: [],
|
||||
isRunningSendQueue: false,
|
||||
|
||||
send: function(envelope, callback) {
|
||||
this.sendQueue.push({
|
||||
envelope: envelope,
|
||||
callback: callback,
|
||||
});
|
||||
send: function(envelope) {
|
||||
this.sendQueue.push(envelope);
|
||||
|
||||
if (!this.isRunningSendQueue) {
|
||||
this.isRunningSendQueue = true;
|
||||
|
@ -58,18 +55,7 @@ var DumbPipe = {
|
|||
},
|
||||
|
||||
runSendQueue: function() {
|
||||
var item = this.sendQueue.shift();
|
||||
|
||||
if (item.callback) {
|
||||
var result = JSON.parse(prompt(JSON.stringify(item.envelope)));
|
||||
try {
|
||||
item.callback(result);
|
||||
} catch(ex) {
|
||||
console.error(ex + "\n" + ex.stack);
|
||||
}
|
||||
} else {
|
||||
alert(JSON.stringify(item.envelope));
|
||||
}
|
||||
alert(JSON.stringify(this.sendQueue.shift()));
|
||||
|
||||
if (this.sendQueue.length > 0) {
|
||||
window.setZeroTimeout(this.runSendQueue.bind(this));
|
||||
|
|
Загрузка…
Ссылка в новой задаче