dispatch:timeout

v0.0.5Published 9 years ago

This package has not had recent updates. Please investigate it's current state before committing to using it in your project.

dispatch:timeout

Helpers to wait for changes with a timeout.

Usage

meteor add dispatch:timeout

API

  • Timeout.interval(testFunc, callback, options);
  • Timeout.autorun(testFunc, callback, options);
  • Timeout.event(eventemitter, event, testFunc, callback, options);

Timeout.interval

Options

  • option.interval defaults to 10ms
  • option.timeout defaults to 10000ms

Example

Here we want to wait for a DOM element to exist, we test existence pr. interval. When it exists or timeout the we call back.

1// A check running on an interval
2Timeout.interval(function() {
3  var elements = $('body').find('.my-element');
4  return elements && elements.length;
5}, function(error) {
6  if (error) {
7    throw new Error('Timed out while waiting for .my-element');
8  } else {
9    console.log('Element .my-element is ready');
10  }
11});

Timeout.autorun

Options

  • option.timeout defaults to 10000ms

Example

Wait for a reactive variable to be true or timeout.

1// A check running on reactive changes
2var reactive = new ReactiveVar(false);
3
4Timeout.autorun(function() {
5  return reactive.get();
6}, function(error) {
7  if (error) {
8    throw new Error('Timed out while waiting for reactive to be true');
9  } else {
10    console.log('Reactive is true.');
11  }
12});
13