diff 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
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/app/services/feature-extraction/FeatureExtractionWorker.ts	Thu Dec 01 15:46:33 2016 +0000
@@ -0,0 +1,27 @@
+/**
+ * Created by lucas on 01/12/2016.
+ */
+
+// 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;
+
+  constructor(workerScope: WorkerGlobalScope) {
+    console.log('ctor');
+    this.workerScope = workerScope;
+    this.workerScope.onmessage = (ev: MessageEvent) => {
+      console.log(ev.data);
+    };
+    let counter = 0;
+    setInterval(() => this.workerScope.postMessage(counter++), 1000);
+  }
+}