Giter Site home page Giter Site logo

maxfierke / ember-procrastination Goto Github PK

View Code? Open in Web Editor NEW
5.0 2.0 0.0 436 KB

No code is more concurrent than code that does not run and then runs all at once, suddenly.

Home Page: https://medium.com/@maxfierke/a-new-concurrency-primitive-39eab08c2494

License: MIT License

JavaScript 83.68% HTML 16.32%
ember ember-addon procrastination ember-concurrency satire

ember-procrastination's Introduction

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:

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

<span>
  Number is: {{num}}
</span>
<pre>
  state = {{regenerateNumber.state}}
  lastExcuse = {{regenerateNumber.lastExcuse}}
</pre>
<br />
<button
  type="button"
  disabled={{regenerateNumber.isRunning}}
  onClick={{procrastinate regenerateNumber}}>
  {{#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}}
</button>

Developing

  • git clone <repository-url> this repository
  • cd ember-procrastination
  • npm install

Running

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/.

ember-procrastination's People

Contributors

ember-tomster avatar maxfierke avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.