Skip to content

Commit

Permalink
ADD completeEverything
Browse files Browse the repository at this point in the history
  • Loading branch information
deepnight committed Oct 31, 2024
1 parent d8649ec commit aa72938
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/dn/Delayer.hx
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,15 @@ class Delayer {
// }
// }

/** Completes all tasks immediately (tasks callbacks will be called) */
public function completeEverything() {
var all = delays.copy();
delays = [];
for(d in all)
d.cb();
}

/** Cancels all tasks (their callbacks won't be called) */
public function cancelEverything() {
delays = [];
}
Expand Down Expand Up @@ -157,6 +166,16 @@ class Delayer {
delayer.cancelById("test");
delayer.update(1);

// Completing all
var n = 0;
delayer.addF("a", ()->n++, 1);
delayer.addF("b", ()->n++, 99);
delayer.addF("c", ()->n++, 99);
delayer.update(1);
CiAssert.equals( n, 1 );
delayer.completeEverything();
CiAssert.equals( n, 3 );

// Next frame
var done = false;
delayer.nextFrame( ()->done=true );
Expand Down

0 comments on commit aa72938

Please sign in to comment.