clydebamford Member Licensed User Longtime User Oct 23, 2017 #1 is there a way to break out of a sleep() before it wakes up so that if something unrelated happens and we no longer want to run the code after sleep we can abort? I've been using a global var and checking that before continue with the code after sleep and I guess thats probably simpler than tring to identify which sleep call to abort!
is there a way to break out of a sleep() before it wakes up so that if something unrelated happens and we no longer want to run the code after sleep we can abort? I've been using a global var and checking that before continue with the code after sleep and I guess thats probably simpler than tring to identify which sleep call to abort!
Erel B4X founder Staff member Licensed User Longtime User Oct 23, 2017 #2 Not directly, but it is possible to "control" the resumable sub without global variables. The exact details depend on your requirements. Can you post more information or code? Upvote 0
Not directly, but it is possible to "control" the resumable sub without global variables. The exact details depend on your requirements. Can you post more information or code?
clydebamford Member Licensed User Longtime User Oct 23, 2017 #3 I'm using exo to play small pieces of a large mp4 on demand and inbetween clips I play another 10 sec clip on a loop using sleep() to loop the clip. It seems to get confused when I try to jump to another frame in another sub and then sleep finishes and tries to pause the video and loop...so basically I'm trying to controll exoplayer from 2 different subs and the sub that has a long sleep takes over when it wakes up, ? Upvote 0
I'm using exo to play small pieces of a large mp4 on demand and inbetween clips I play another 10 sec clip on a loop using sleep() to loop the clip. It seems to get confused when I try to jump to another frame in another sub and then sleep finishes and tries to pause the video and loop...so basically I'm trying to controll exoplayer from 2 different subs and the sub that has a long sleep takes over when it wakes up, ?
Erel B4X founder Staff member Licensed User Longtime User Oct 23, 2017 #4 I think that you should use a global variable for this case. Create a global TaskIndex int variable and use it like this: Code: Copy Sub ThisIsTheResumableSub TaskIndex = TaskIndex + 1 Dim MyTask As Int = TaskIndex '... Sleep(...) If MyTask <> TaskIndex Then Return Canceling the current waiting sub is simple as writing: TaskIndex = TaskIndex + 1 You can see this pattern in Camera2 class which is completely asynchronous. Upvote 0
I think that you should use a global variable for this case. Create a global TaskIndex int variable and use it like this: Code: Copy Sub ThisIsTheResumableSub TaskIndex = TaskIndex + 1 Dim MyTask As Int = TaskIndex '... Sleep(...) If MyTask <> TaskIndex Then Return Canceling the current waiting sub is simple as writing: TaskIndex = TaskIndex + 1 You can see this pattern in Camera2 class which is completely asynchronous.
clydebamford Member Licensed User Longtime User Oct 23, 2017 #5 nice!, thanks for that. I was using a booleon var but I guess your way will avoid problems with multiple reuseable subs, cheers! Last edited: Oct 23, 2017 Upvote 0
nice!, thanks for that. I was using a booleon var but I guess your way will avoid problems with multiple reuseable subs, cheers!