-
-
Save nightire/2f8dfcc0308d7304fc7fadef36e7f77b to your computer and use it in GitHub Desktop.
Event stream based task
This file contains hidden or 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* () { | |
while (true) { | |
let payload = yield waitForEvent(this, 'message'); | |
this.get('messages').pushObject(payload); | |
} | |
}), | |
init() { | |
this._super(...arguments); | |
this.set('messages', []); | |
this.get('myTask').perform(); | |
setInterval(() => { | |
let randomLetters = [1, 2, 3, 4] | |
.map(() => String.fromCharCode(Math.floor(Math.random() * 26) + 65)) | |
.join(''); | |
this.trigger('message', randomLetters); | |
}, 1000); | |
} | |
}); |
This file contains hidden or 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