Timers
Meteor uses global environment variables to keep track of things like the current request’s user. To make sure these variables have the right values, you need to use Meteor.setTimeout
instead of setTimeout
and Meteor.setInterval
instead of setInterval
.
These functions work just like their native JavaScript equivalents. If you call the native function, you’ll get an error stating that Meteor code must always run within a Fiber, and advising to use Meteor.bindEnvironment
.
Anywhere Meteor.setTimeout(func, delay)
import { Meteor } from 'meteor/meteor'
(meteor/timers.js, line 28)
import { Meteor } from 'meteor/meteor'
(meteor/timers.js, line 28) Call a function in the future after waiting for a specified delay.
Arguments
-
func
Function -
The function to run
-
delay
Number -
Number of milliseconds to wait before calling function
Returns a handle that can be used by Meteor.clearTimeout
.
Anywhere Meteor.setInterval(func, delay)
import { Meteor } from 'meteor/meteor'
(meteor/timers.js, line 39)
import { Meteor } from 'meteor/meteor'
(meteor/timers.js, line 39) Call a function repeatedly, with a time delay between calls.
Arguments
-
func
Function -
The function to run
-
delay
Number -
Number of milliseconds to wait between each function call.
Returns a handle that can be used by Meteor.clearInterval
.
Anywhere Meteor.clearTimeout(id)
import { Meteor } from 'meteor/meteor'
(meteor/timers.js, line 59)
import { Meteor } from 'meteor/meteor'
(meteor/timers.js, line 59) Cancel a function call scheduled by Meteor.setTimeout
.
Arguments
-
id
Number -
The handle returned by
Meteor.setTimeout
Anywhere Meteor.clearInterval(id)
import { Meteor } from 'meteor/meteor'
(meteor/timers.js, line 49)
import { Meteor } from 'meteor/meteor'
(meteor/timers.js, line 49) Cancel a repeating function call scheduled by Meteor.setInterval
.
Arguments
-
id
Number -
The handle returned by
Meteor.setInterval
© 2011–2017 Meteor Development Group, Inc.
Licensed under the MIT License.
https://docs.meteor.com/v1.3.5/api/timers.html