Meteor Tutorial
Meteor Useful Resources
Selected Reading
- Meteor - Best Practices
- Meteor - ToDo App
- Meteor - Running on mobile
- Meteor - Deployment
- Meteor - Structure
- Meteor - Publish & Subscribe
- Meteor - Package.js
- Meteor - Methods
- Meteor - Accounts
- Meteor - Sorting
- Meteor - Security
- Meteor - Assets
- Meteor - Email
- Meteor - HTTP
- Meteor - EJSON
- Meteor - Timers
- Meteor - Blaze
- Meteor - Check
- Meteor - Core API
- Meteor - Packages
- Meteor - Tracker
- Meteor - Session
- Meteor - Events
- Meteor - Forms
- Meteor - Collections
- Meteor - Templates
- Meteor - First Application
- Meteor - Environment Setup
- Meteor - Overview
- Meteor - Home
Meteor Useful Resources
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
Meteor - Timers
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 pke 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.
![Meteor Timeout](/meteor/images/meteor-timeout.jpg)
Interval
Following example shows how to set and clear an interval.
meteorApp.html
<head> <title>meteorApp</title> </head> <body> <span> {{> myTemplate}} </span> </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.isCpent) { var counter = 0; var myInterval = Meteor.setInterval(function() { counter ++ console.log("Interval called " + counter + " times..."); }, 3000); Template.myTemplate.events({ cpck 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 cpcking the CLEAR button. This will call the clearInterval method.
![Meteor Interval](/meteor/images/meteor-interval.jpg)