https://github.com/maxfierke/ember-procrastination
No code is more concurrent than code that does not run and then runs all at once, suddenly.
https://github.com/maxfierke/ember-procrastination
ember ember-addon ember-concurrency procrastination satire
Last synced: about 1 year ago
JSON representation
No code is more concurrent than code that does not run and then runs all at once, suddenly.
- Host: GitHub
- URL: https://github.com/maxfierke/ember-procrastination
- Owner: maxfierke
- License: mit
- Created: 2017-05-30T17:20:26.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2017-06-01T01:49:00.000Z (about 9 years ago)
- Last Synced: 2025-04-23T17:12:03.658Z (about 1 year ago)
- Topics: ember, ember-addon, ember-concurrency, procrastination, satire
- Language: JavaScript
- Homepage: https://medium.com/@maxfierke/a-new-concurrency-primitive-39eab08c2494
- Size: 426 KB
- Stars: 5
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# ember-procrastination
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.
## Overview
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.
## Installation
```
$ ember install ember-procrastination
```
## Example
controller.js:
```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
```hbs
Number is: {{num}}
state = {{regenerateNumber.state}}
lastExcuse = {{regenerateNumber.lastExcuse}}
{{#if (and regenerateNumber.isProcrastinating regenerateNumber.lastExcuse)}}
{{regenerateNumber.lastExcuse}}
{{else if regenerateNumber.isRunning}}
Doing the thing...
{{else if regenerateNumber.isQueued}}
Ugh... Why do you keep asking me to do stuff?
{{else}}
Do the Thing
{{/if}}
```
## Developing
* `git clone ` this repository
* `cd ember-procrastination`
* `npm install`
### Running
* `ember serve`
* Visit your app at [http://localhost:4200](http://localhost:4200).
### Running Tests
* `npm test` (Runs `ember try:each` to test your addon against multiple Ember versions)
* `ember test`
* `ember test --server`
### Building
* `ember build`
For more information on using ember-cli, visit [https://ember-cli.com/](https://ember-cli.com/).