-
-
Save alexmiddeleer/8898fc48c717bfa45a2e4907367b6298 to your computer and use it in GitHub Desktop.
Event stream based task
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Ember from 'ember'; | |
import { task, waitForEvent } from 'ember-concurrency'; | |
const { Evented, Controller } = Ember; | |
export default Controller.extend(Evented, { | |
myTask: task(function* (payload) { | |
this.get('messages').pushObject(payload); | |
}), | |
init() { | |
this._super(...arguments); | |
this.set('messages', []); | |
setInterval(() => { | |
let randomLetters = [1, 2, 3, 4] | |
.map(() => String.fromCharCode(Math.floor(Math.random() * 26) + 65)) | |
.join(''); | |
this.get('myTask').perform(randomLetters); | |
}, 1000); | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"version": "0.15.0", | |
"EmberENV": { | |
"FEATURES": {} | |
}, | |
"options": { | |
"use_pods": false, | |
"enable-testing": false | |
}, | |
"dependencies": { | |
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.js", | |
"ember": "3.2.2", | |
"ember-template-compiler": "3.2.2", | |
"ember-testing": "3.2.2" | |
}, | |
"addons": { | |
"ember-data": "3.2.0", | |
"ember-concurrency": "0.8.19" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment