Skip to content

Instantly share code, notes, and snippets.

@benjaminjackman
Last active May 25, 2016 00:49
Show Gist options
  • Save benjaminjackman/166530a2e076966493a7aadf09e0eb23 to your computer and use it in GitHub Desktop.
Save benjaminjackman/166530a2e076966493a7aadf09e0eb23 to your computer and use it in GitHub Desktop.
import org.scalajs.dom
import org.scalajs.dom.raw.Blob
import org.scalajs.dom.raw.BlobPropertyBag
import org.scalajs.dom.raw.Worker
import scala.scalajs.js
import scala.scalajs.js.annotation.JSExport
@JSExport("AlphaWorkerMain")
object AlphaWorkerMain {
@JSExport
def main() {
console.log("AlphaWorkerMain Called")
}
}
object Samples {
def startWebWorker() {
console.log("Start web worker sample")
val bootCode = """
try {
importScripts('http://localhost:9001/sjs/viz-sjs-fastopt.js');
} catch(e) {
console.trace(e);
}
console.log("data uri code executing");
AlphaWorkerMain().main();
"""
val blob = new Blob(js.Array(bootCode), BlobPropertyBag("application/javascript"))
val URL = global.URL.asInstanceOf[dom.raw.URL]
val worker = new Worker(URL.createObjectURL(blob))
// def f(e: MessageEvent): Unit = {
// console.log("Response ", e)
// }
// worker.onmessage = (x: js.Any) => f(x.asInstanceOf[MessageEvent])
// worker.postMessage(OBJ(foo = "bar"))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment