Skip to content

Instantly share code, notes, and snippets.

@ollpu
Created November 26, 2014 15:18
Show Gist options
  • Save ollpu/cf0b077612f9b574bd12 to your computer and use it in GitHub Desktop.
Save ollpu/cf0b077612f9b574bd12 to your computer and use it in GitHub Desktop.
Scheduler Demo
scheduler sched = new scheduler("drawSomething");
void setup() {
size(500, 500);
sched.scheduleLoopingTask(1000);
frameRate(2);
}
void draw() {
background(0);
}
void callSchedulerDoWork() {
sched.doWork();
}
class scheduler {
int timer;
boolean timing;
String call;
scheduler(String whatToCall) {
timer = 0;
call = whatToCall;
}
void scheduleLoopingTask(int interval) {
timer = interval;
timing = true;
thread("callSchedulerDoWork");
}
void stop() {
timing = false;
}
//Requires to be executed in a thread to not obstruct rest of the program
void doWork() {
while (timing) {
thread(call);
delay(timer);
}
}
}
void drawSomething() {
println("jeee");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment