Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
let obs = window.Rx.Observable.interval(100).take(50 + 1).do(v => {
if (!this.isDestroyed) {
this.set('obsValue', v);
}
});
let ai = asyncIterator(obs);
if (this.bufferType) {
ai[this.bufferType]();
}
while (true) {
let { value, done } = yield ai.next();
if (done) { break; }
this.set('value', value);
yield sleep(300); // pretend to be some async work
}
}).autoStart(),
beepOscillator.frequency.value = 300;
let beepGain = context.createGain();
beepGain.gain.value = 0;
beepOscillator.connect(beepGain);
beepOscillator.type = 'triangle';
beepGain.connect(context.destination);
beepOscillator.start(0);
let bps = this.get('bpm') / 60.0;
let halfTimeout = 1 / bps / 2 * 1000;
// sleep randomly so that multiple x-musics don't annoying start at the same time.
yield sleep(Math.random() * 1000);
for (;;) {
// main
beepOscillator.frequency.value = 100 + Math.random() * 600;
beepGain.gain.setTargetAtTime(0.5, context.currentTime, 0.01);
this.set('isPlaying', true);
yield sleep(halfTimeout);
beepGain.gain.setTargetAtTime(0, context.currentTime, 0.01);
this.set('isPlaying', false);
yield sleep(halfTimeout);
}
} finally {
if (context) {
context.close();
}
myTask: task(function * () {
this.set('value', "START");
let ai = asyncIterator.fromEvent(this, 'onEvent');
if (this.bufferType) {
ai[this.bufferType]();
}
while (true) {
let { value, done } = yield ai.next();
if (done) { break; }
this.set('value', value.foo);
yield sleep(800); // pretend to be some async work
}
}).autoStart(),
beepGain.connect(context.destination);
beepOscillator.start(0);
let bps = this.get('bpm') / 60.0;
let halfTimeout = 1 / bps / 2 * 1000;
// sleep randomly so that multiple x-musics don't annoying start at the same time.
yield sleep(Math.random() * 1000);
for (;;) {
// main
beepOscillator.frequency.value = 100 + Math.random() * 600;
beepGain.gain.setTargetAtTime(0.5, context.currentTime, 0.01);
this.set('isPlaying', true);
yield sleep(halfTimeout);
beepGain.gain.setTargetAtTime(0, context.currentTime, 0.01);
this.set('isPlaying', false);
yield sleep(halfTimeout);
}
} finally {
if (context) {
context.close();
}
if (beepOscillator) {
beepOscillator.stop();
}
}
}).autoStart(),
playMusic: task(function * () {
let i = 0;
while(i++ < 6) {
this.set('value', i);
yield sleep(150);
}
let AudioContext = window.AudioContext || window.webkitAudioContext;
if (!AudioContext) {
console.error("AudioContext not detected... perhaps web audio api not supported?");
return;
}
let context, beepOscillator;
try {
context = new AudioContext();
beepOscillator = context.createOscillator();
beepOscillator.frequency.value = 300;
task: task('group', function * () {
let i = 0;
while(i++ < 6) {
this.set('value', i);
yield sleep(150);
}
}),
colorAlternator: process(function * () {
let colors = ['red', 'blue', 'green'];
for (;;) {
for (let color of colors) {
this.set('color', color);
yield sleep(this.get('ms'));
}
}
}),
wikiSearcher: process(function * (query) {
this.set('progress', 0.1);
let countdown = 4;
while (countdown--) {
this.set('status', `Gearing up for an AJAX query in ${countdown}`);
this.set('progress', this.get('progress') + 0.02);
yield sleep(1000);
}
this.set('status', `Performing AJAX query for ${query}...`);
this.set('progress', 0.5);
let encodedQuery = window.encodeURIComponent("query");
let url = `https://en.wikipedia.org/w/api.php?action=opensearch&format=json&search=${encodedQuery}&callback=?`;
let ajaxRequest = Ember.$.getJSON(url);
try {
let response = Ember.RSVP.resolve(ajaxRequest.promise());
this.set('status', "Search complete!");
this.set('progress', 1);
let results = response[3];
this.set('results', results);