comparison src/app/services/feature-extraction/FeatureExtractionWorker.ts @ 40:f7244f2155a3

Setup some scaffolding for bootstrapping a worker and loading into a service, providing a mechanism for implementing most of the logic which runs inside the worker in TypeScript.
author Lucas Thompson <dev@lucas.im>
date Thu, 01 Dec 2016 15:46:33 +0000
parents
children 13f5f228ed98
comparison
equal deleted inserted replaced
39:e6eb133fa47c 40:f7244f2155a3
1 /**
2 * Created by lucas on 01/12/2016.
3 */
4
5 // TODO TypeScript has a .d.ts file for webworkers, but for some reason it clashes with the typings for dom and causes compiler errors
6 interface WorkerGlobalScope {
7 onmessage: (this: this, ev: MessageEvent) => any;
8 postMessage(data: any): void;
9 }
10
11 interface MessageEvent {
12 readonly data: any;
13 }
14
15 export default class FeatureExtractionWorker {
16 private workerScope: WorkerGlobalScope;
17
18 constructor(workerScope: WorkerGlobalScope) {
19 console.log('ctor');
20 this.workerScope = workerScope;
21 this.workerScope.onmessage = (ev: MessageEvent) => {
22 console.log(ev.data);
23 };
24 let counter = 0;
25 setInterval(() => this.workerScope.postMessage(counter++), 1000);
26 }
27 }