summaryrefslogtreecommitdiff
path: root/threads.js
diff options
context:
space:
mode:
authorBernat Romagosa <bromagosa@dosta.net>2014-11-17 14:05:13 +0100
committerBernat Romagosa <bromagosa@dosta.net>2014-11-17 14:05:13 +0100
commitf537f62ace4092e1f46d0ca54577ea8810e7510a (patch)
tree0285fcc5ac23684ccfd612b1db4eae353d080cd7 /threads.js
parentea05f7859fe5a042f0c0dd49b189c594b9a798d3 (diff)
downloadsnap-byow-f537f62ace4092e1f46d0ca54577ea8810e7510a.tar.gz
snap-byow-f537f62ace4092e1f46d0ca54577ea8810e7510a.zip
Added callback to Process
Diffstat (limited to 'threads.js')
-rw-r--r--threads.js17
1 files changed, 10 insertions, 7 deletions
diff --git a/threads.js b/threads.js
index cf97362..4592e92 100644
--- a/threads.js
+++ b/threads.js
@@ -136,7 +136,8 @@ ThreadManager.prototype.toggleProcess = function (block) {
ThreadManager.prototype.startProcess = function (
block,
isThreadSafe,
- exportResult
+ exportResult,
+ callback
) {
var active = this.findProcess(block),
top = block.topBlock(),
@@ -149,7 +150,7 @@ ThreadManager.prototype.startProcess = function (
this.removeTerminatedProcesses();
}
top.addHighlight();
- newProc = new Process(block.topBlock());
+ newProc = new Process(block.topBlock(), callback);
newProc.exportResult = exportResult;
this.processes.push(newProc);
return newProc;
@@ -314,6 +315,7 @@ ThreadManager.prototype.findProcess = function (block) {
and when the process was paused
exportResult boolean flag indicating whether a picture of the top
block along with the result bubble shoud be exported
+ callback a function to be executed when the process is done
*/
Process.prototype = {};
@@ -321,7 +323,7 @@ Process.prototype.contructor = Process;
Process.prototype.timeout = 500; // msecs after which to force yield
Process.prototype.isCatchingErrors = true;
-function Process(topBlock) {
+function Process(topBlock, callback) {
this.topBlock = topBlock || null;
this.readyToYield = false;
@@ -338,6 +340,7 @@ function Process(topBlock) {
this.pauseOffset = null;
this.frameCount = 0;
this.exportResult = false;
+ this.callback = callback;
if (topBlock) {
this.homeContext.receiver = topBlock.receiver();
@@ -435,8 +438,8 @@ Process.prototype.pauseStep = function () {
Process.prototype.evaluateContext = function () {
var exp = this.context.expression;
-
this.frameCount += 1;
+
if (exp instanceof Array) {
return this.evaluateSequence(exp);
}
@@ -476,9 +479,9 @@ Process.prototype.evaluateBlock = function (block, argCount) {
}
if (this.isCatchingErrors) {
try {
- this.returnValueToParentContext(
- rcvr[block.selector].apply(rcvr, inputs)
- );
+ var result = rcvr[block.selector].apply(rcvr, inputs);
+ if (this.callback) { this.callback(result) };
+ this.returnValueToParentContext(result);
this.popContext();
} catch (error) {
this.handleError(error, block);