No description
  • JavaScript 89.5%
  • HTML 8.2%
  • Handlebars 2.3%
Find a file
Lisbet Alvarez 6d2a8ef188
Update readme with deprecation warning (#13)
* Update readme with deprecated message
2025-03-06 13:50:19 -08:00
.github/workflows update deps - node (#11) 2024-07-11 09:29:48 -07:00
addon feature: implement runEvery route method decorator and add tests 2021-12-26 15:54:50 -05:00
addon-test-support feature: add test helpers 2021-12-28 16:55:06 -05:00
app feature: initial pollster service implementation 2021-12-26 11:01:56 -05:00
config ci: remove failed ember try scenarios 2021-12-26 12:50:56 -05:00
tests feature: add test helpers 2021-12-28 16:55:06 -05:00
vendor Initial Commit from Ember CLI v4.0.1 2021-12-24 17:44:50 -05:00
.editorconfig Initial Commit from Ember CLI v4.0.1 2021-12-24 17:44:50 -05:00
.ember-cli Initial Commit from Ember CLI v4.0.1 2021-12-24 17:44:50 -05:00
.eslintignore Initial Commit from Ember CLI v4.0.1 2021-12-24 17:44:50 -05:00
.eslintrc.js Initial Commit from Ember CLI v4.0.1 2021-12-24 17:44:50 -05:00
.gitignore Initial Commit from Ember CLI v4.0.1 2021-12-24 17:44:50 -05:00
.npmignore Initial Commit from Ember CLI v4.0.1 2021-12-24 17:44:50 -05:00
.prettierignore Initial Commit from Ember CLI v4.0.1 2021-12-24 17:44:50 -05:00
.prettierrc.js Initial Commit from Ember CLI v4.0.1 2021-12-24 17:44:50 -05:00
.template-lintrc.js Initial Commit from Ember CLI v4.0.1 2021-12-24 17:44:50 -05:00
.watchmanconfig Initial Commit from Ember CLI v4.0.1 2021-12-24 17:44:50 -05:00
CONTRIBUTING.md Initial Commit from Ember CLI v4.0.1 2021-12-24 17:44:50 -05:00
ember-cli-build.js Initial Commit from Ember CLI v4.0.1 2021-12-24 17:44:50 -05:00
index.js Initial Commit from Ember CLI v4.0.1 2021-12-24 17:44:50 -05:00
LICENSE.md Initial Commit from Ember CLI v4.0.1 2021-12-24 17:44:50 -05:00
package-lock.json add 22 support (#12) 2025-02-13 09:18:00 -08:00
package.json add 22 support (#12) 2025-02-13 09:18:00 -08:00
README.md Update readme with deprecation warning (#13) 2025-03-06 13:50:19 -08:00
testem.js Initial Commit from Ember CLI v4.0.1 2021-12-24 17:44:50 -05:00

DEPRECATED

This project is no longer maintained, please consider using ember-concurrency instead.

ember-pollster

Ember Pollster is a simple polling service designed for deterministically testable applications. It replaces heavyweight solutions like Ember Concurrency for many use cases.

Ember Pollster is compatible with Ember v4.0.

Compatibility

  • Ember.js v3.28, v4.0, and above
  • Ember CLI v3.28, v4.0, and above
  • Node.js v20 and above

Installation

ember install ember-pollster

Usage

Ember Pollster enables two usage modes: one for automatic route polling and another for manual polling use cases. Both cases are easy to test in an explicit, deterministic manner.

Route Polling

A route poller is just a plain method on your route, decorated by @runEvery(millseconds). Polling route methods are automatically managed by Ember Pollster ensuring the following conditions are met:

  • Polling is activated when the route enters.
  • Polling is deactivated when the route exits.
  • In a testing environment, polling does not run automatically and must be explicitly executed via the included test helpers.

For example:

import Route from '@ember/routing/route';
import runEvery from 'ember-pollster/decorators/route/run-every';

export default class MyRoute extends Route {
  model() {
    // ... make API request
  }

  // This method automatically executes every second when this route
  // (or its children) is active.  Since it's just a plain method, it may still
  // be called like one as needed.
  @runEvery(1000)
  poller() {
    this.refresh();
  }
}

Service Usage

Need to setup and run polling manually? No problem. Ember Pollster exposes a service for this use case:

@service pollster;

createJobAndStartPolling() {
  // Either bind the function to the context first OR pass an arrow function.
  const fn = () => this.poller();
  // Call `findOrCreateJob` to avoid creating multiple jobs
  // for the same function.
  this.job = this.pollster.findOrCreateJob(fn, 1000);
  this.job.start();
}

tearDown() {
  this.job.stop();
}

poller() {
  // do something repeatedly
}

Just remember to manually stop polling with job.stop().

Explicit Testing

To test applications that use Ember Pollster, first import the test helpers:

import { runAllJobs, hasRunningJobs } from 'ember-pollster/test-support';

To explicitly run jobs as needed throughout your tests, use await runAllJobs(). This test helper executes any jobs in a "running" state (for example, jobs on a currently active route), ignoring jobs that aren't running. Note that in a testing environment jobs do not execute automatically even when they are in a "running" state. This ensures deterministic testing.

await runAllJobs();

Contributing

See the Contributing guide for details.

License

This project is licensed under the MIT License.