Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import Component from '@glimmer/component';
import { tracked } from '@glimmer/tracking';
import { timeout } from 'ember-concurrency';
import { task, lastValue } from 'ember-concurrency-decorators';
export default class AsyncButton extends Component {
@tracked clickCount = 0;
// get lastCoords() {
// return this.clickTask.lastSuccessful.value;
// }
@lastValue('clickTask') lastCoords!: string;
@task
clickTask = function*(e: MouseEvent) {
yield timeout(2000);
this.clickCount++;
return `${e.x} x ${e.y}`;
};
}
}
play(track: Track): any {
if (this.controller && this.task) {
this.controller.abort();
this.controller = new AbortController();
this.signal = this.controller.signal;
this.task.cancel();
}
// @ts-ignore
this.task = this._load.perform(track);
return this.task;
}
// @ts-ignore
@task({ maxConcurrency: 2, drop: true })
*_load(track: Track): any {
let audio;
const options = { method: 'get', signal: this.signal };
try {
this.audio.pause();
const queryParams = encodeURI(`?artist=${track.artist}&song=${track.name}`);
const response = yield fetch(this.host + this.endpoint + queryParams, options);
const data = yield response.json();
audio = decodeURIComponent(data.video);
this.audio.play(audio);
} catch(error) {
this.audio.tracksManager.nextPlay();
}
return audio;