
- Meteor Tutorial
- Meteor - Home
- Meteor - Overview
- Meteor - Environment Setup
- Meteor - First Application
- Meteor - Templates
- Meteor - Collections
- Meteor - Forms
- Meteor - Events
- Meteor - Session
- Meteor - Tracker
- Meteor - Packages
- Meteor - Core API
- Meteor - Check
- Meteor - Blaze
- Meteor - Timers
- Meteor - EJSON
- Meteor - HTTP
- Meteor - Email
- Meteor - Assets
- Meteor - Security
- Meteor - Sorting
- Meteor - Accounts
- Meteor - Methods
- Meteor - Package.js
- Meteor - Publish & Subscribe
- Meteor - Structure
- Meteor - Deployment
- Meteor - Running on mobile
- Meteor - ToDo App
- Meteor - Best Practices
- Meteor Useful Resources
- Meteor - Quick Guide
- Meteor - Useful Resources
- Meteor - Discussion
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Meteor - Timers
Meteor offers its own setTimeout and setInterval methods. These methods are used to make sure that all global variables have correct values. They work like regular JavaScript setTimout and setInterval.
Timeout
This is Meteor.setTimeout example.
Meteor.setTimeout(function() { console.log("Timeout called after three seconds..."); }, 3000);
We can see in the console that the timeout function is called once the app has started.

Interval
Following example shows how to set and clear an interval.
meteorApp.html
<head> <title>meteorApp</title> </head> <body> <div> {{> myTemplate}} </div> </body> <template name = "myTemplate"> <button>CLEAR</button> </template>
We will set the initial counter variable that will be updated after every interval call.
meteorApp.js
if (Meteor.isClient) { var counter = 0; var myInterval = Meteor.setInterval(function() { counter ++ console.log("Interval called " + counter + " times..."); }, 3000); Template.myTemplate.events({ 'click button': function() { Meteor.clearInterval(myInterval); console.log('Interval cleared...') } }); }
The console will log the updated counter variable every three seconds. We can stop this by clicking the CLEAR button. This will call the clearInterval method.

Advertisements