Wait for running Task to complete
How do I make a program wait for a running task to complete?
Tried stuff like but it doesn't wait for the task to be canceled.
function tsk() {
if (shouldDoSomething) {
arguments.callee.task.repeat();
}
else {
arguments.callee.task.cancel();
}
}
thingToDo = new Task(tsk, this);
thingToDo.execute();
doStuffAfterTask = stuff;
I am trying to wait for a scene to stop recording in M4L, and the only attribute I can monitor is "is_triggered".
i can think of few solutions . can u write down what is causing task to start and what condition should be checked in order to "finish" task ... or other things ? whats is the main logic ?
var tsk = function(){
print()
arguments.callee.task.repeat();
};
var print = function(){
post("repeating\n")
};
var run = new Task(tsk) ;
///////////////////////////////////////
var stop = function(){
run.cancel()
};
var start = function(){
run.execute()
};
var promise = false ;
var isRunning = false ;
var tsk = function(){
if(promise){
arguments.callee.task.cancel();
afterAll()
promise = false ;
isRunning = false ;
arguments.callee.task.execute();
}else{
isRunning = true ;
arguments.callee.task.schedule(300);
print()
}
};
var print = function(){
post(run.running,"\n")
};
var afterAll = function(){
post("ater task\n")
}
var run = new Task(tsk) ;
///////////////////////////////////////
var stop = function(){
run.cancel()
};
var start = function(){
if(!isRunning){
run.execute()
}else{
promise = true ;
}
};
or setting a "promise" to execute
I appreciate your reply DO...WHILE!
The main thing is I want to use a Task as the equivalent of a sleep() function or Javascript setTimeOut() that checks on the value of a variable after a certain time frame and stops other things from happening for that time. Or something that at least executes delayed--I can write it so that other things don't happen till it's done.
Your responses make perfect sense to me but I really just need something simple that does the equivalent of (though I realize this particular code will crash the computer):
while (task.running()) {
task.repeat(1,250) //run the task, i.e. check a variable value.
}
var done = 1; //this doesn't happen until the task completes
I actually can't get a Task in any form to run at all. There is something weird about the architecture that I'm not understanding.
Something as simple as below never posts 'this happened':
function after_record_callback() {
/*this is being called correctly after I'm done recording something in Live */
duplicator = new Task(function() { post('this happened'); });
duplicator.repeat(1,250); //never posts 'this happened'
duplicator.schedule(250); //never posts 'this happened'
}
WHY? Is it something to do with M4L?
Appreciate your help!
Hi
your while loop executes and never finishes , it repeats whats in his body until crash . you are trying to set "repeat" and "delay" on every loop , why ?
Also , maybe its a typo here but "task.running()" is not a function . condition passes always because at first its a member of a task object .
im not quite sure what u are trying to do if non of my examples didnt get you near there yet ... u said delayed execution ... well "schedule" is appropriate candidate for that ...
considering your "use" . are u trying to check in task loop if your clip is in recording process in order to run some function while its finished ?
you can do in with condition check inside task , and set delay for next check . this is your sleep in this case
var tsk = function(){
if(somethingRunning){
arguments.callee.task.schedule(300);
}else{
/// your stuff
}
};
let me know how u feel it
# EDIT
seeing you first post . u were there actually . your if statement should check if your recording is in progress . whenever u use repeat or schedule should do the job .
alternatively u may want to work with LiveAPI observer callback that may notify about events youre trying to observe
Ok so I know the while loop is not the right answer. I just wanted something that does: 1. check a variable, 2. WAIT 3. check again. Sorry if I've been unclear
I am doing exactly what you suggest:
1. I am using a LiveAPI observer which monitors "is_triggered" on a scene, and will thus give me information about when the recording is done.
However, I can't use the callback to trigger further changes in Live because I get an error "Changes cannot be triggered by notifications" which I know will be resolved by WAITING before I call the next action.
2. This is why I have this code:
function after_record_callback() {
/*this is being called correctly after I'm done recording something in Live */
duplicator = new Task(function() { post('this happened'); });
duplicator.repeat(1,250); //never posts 'this happened'
duplicator.schedule(250); //never posts 'this happened'
}
My problem is that the function within the Task ("duplicator") never runs and I'm wondering why.
Thanks for your help.
For some reason
task.schedule(250) never runs the task.
But what worked for me was
task.execute() with scheduling done within the task, as you suggested.
I.e.
var task = new Task(function() { post('this happened'); arguments.callee.task.schedule(250); });
will post 'this happened' every 250 ms.
Thanks!
im really not able to guess what is up .if u dont mind ,please Zip your device with Js file . let me see it
#EDIT
did not seen last answer . so its okay ?
function after_record_callback() {
/*this is being called correctly after I'm done recording something in Live */
duplicator = new Task(function() {post('this happened'); });
duplicator.repeat(1,250); //never posts 'this happened'
duplicator.schedule(250); //never posts 'this happened' }
I am sorry for bumping the old thread, but I desperately need the answer for this unanswered question (blessed be the answerer): Why does duplicator.repeat and .schedule not doing their job? I have run into the same trouble.