Did you know that almost no language implements procrastination primitives? Of
course, Java offers a ProcrastinationFactory
, .NET has System.Enterprise.ProcrastinationServices
and Haskell has that powerful Procrastinate
monad. However, to date no one has
ever implemented anything like this for Ember or JavaScript. Sad.
ember-procrastination introduces a new concurrency primitive called a someday
.
A someday
is a lot like a task
from ember-concurrency, but has the special
property that it will only schedule and do work when prompted several times.
This means that only work the user truly wants done will get completed. But be
careful: if you ask too much, it may get mad and cancel work already in-progress.
Such truly concurrent code can be finicky.
ember-procrastination also leverages the best in lazy code loading technology to
ensure that we don’t execute expensive operations until the last possible moment.
To do this, ember-procrastination uses an advanced Just-In-Time (JIT) feature
present in modern JavaScript: the beforeunload
event. When ember-procrastination
detects this event, all code that has been previously prompted to run that has
not yet been run will run, ensuring that all work is completed. And it all
happens concurrently. Amazing.
$ ember install ember-procrastination
controller.js:
import Ember from 'ember';
import { someday } from 'ember-procrastination';
import { timeout } from 'ember-concurrency';
export default Ember.Controller.extend({
regenerateNumber: someday(function* () {
this.set('num', Math.random());
yield timeout(1000);
})
});
template.hbs
git clone <repository-url>
this repositorycd ember-procrastination
npm install
ember serve
- Visit your app at http://localhost:4200.
npm test
(Runsember try:each
to test your addon against multiple Ember versions)ember test
ember test --server
ember build
For more information on using ember-cli, visit https://ember-cli.com/.