Mercurial > hg > ugly-duckling
view src/app/services/feature-extraction/FeatureExtractionWorker.ts @ 44:13f5f228ed98
Add a component for the feature extraction menu, and start setting up some comms with the worker. Currently populating a select box with list of extractors from hardcoded server.
author | Lucas Thompson <dev@lucas.im> |
---|---|
date | Fri, 02 Dec 2016 16:55:14 +0000 |
parents | f7244f2155a3 |
children | 933c64ebcd13 |
line wrap: on
line source
/** * Created by lucas on 01/12/2016. */ import {ListResponse, EmscriptenProxy} from 'piper'; import {PiperSimpleClient} from 'piper/HigherLevelUtilities'; import { VampExamplePlugins } from 'piper/ext/VampExamplePluginsModule'; // TODO TypeScript has a .d.ts file for webworkers, but for some reason it clashes with the typings for dom and causes compiler errors interface WorkerGlobalScope { onmessage: (this: this, ev: MessageEvent) => any; postMessage(data: any): void; } interface MessageEvent { readonly data: any; } export default class FeatureExtractionWorker { private workerScope: WorkerGlobalScope; private piperClient: PiperSimpleClient; constructor(workerScope: WorkerGlobalScope) { this.workerScope = workerScope; let counter = 0; setInterval(() => this.workerScope.postMessage(counter++), 1000); this.piperClient = new PiperSimpleClient(new EmscriptenProxy(VampExamplePlugins())); this.workerScope.onmessage = (ev: MessageEvent) => { switch (ev.data.method) { case 'list': this.piperClient.list({}).then(this.workerScope.postMessage); } }; } }