Function

Module: @ember/runloop
import { cancel } from '@ember/runloop';
timer
Object
Timer object to cancel
returns
Boolean
true if canceled or false/undefined if it wasn't found

Cancels a scheduled item. Must be a value returned by run.later(), run.once(), run.scheduleOnce(), run.next(), run.debounce(), or run.throttle().

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
let runNext = run.next(myContext, function() {
  // will not be executed
});

run.cancel(runNext);

let runLater = run.later(myContext, function() {
  // will not be executed
}, 500);

run.cancel(runLater);

let runScheduleOnce = run.scheduleOnce('afterRender', myContext, function() {
  // will not be executed
});

run.cancel(runScheduleOnce);

let runOnce = run.once(myContext, function() {
  // will not be executed
});

run.cancel(runOnce);

let throttle = run.throttle(myContext, function() {
  // will not be executed
}, 1, false);

run.cancel(throttle);

let debounce = run.debounce(myContext, function() {
  // will not be executed
}, 1);

run.cancel(debounce);

let debounceImmediate = run.debounce(myContext, function() {
  // will be executed since we passed in true (immediate)
}, 100, true);

// the 100ms delay until this method can be called again will be canceled
run.cancel(debounceImmediate);