Pages

Web Worker and current Dartlang

Friday, June 13, 2014
Recently I've been researching WebAudio and WebRTC getUserMedia for my personal project.
I googled, then I found the library which really fits my need. http://audior.ec/recordmp3js/ aaaa http://nusofthq.com/blog/recording-mp3-using-only-html5-and-javascript-recordmp3-js/
The library uses WebWorker for audio recording and mp3 conversion to (I guess and probably true) offload the CPU intensive works. I want to write webapp in Dartlang, and it's not serious project, so I'm trying to port this JS library to Dart for my study. (Yes, you know, probably I can (should?) just use this library by dart:js.) So I have a chance to try Web Worker in Dart.
Without much thought, I tried the porting, wrote the WebWorkers in Dart, and I stumbled into that a WebWorker itself should be written in JS, not Dart.
Here is the simple sample code. https://github.com/ntaoo/web_worker_sample
The JS version WebWorker should work normally, and Dart version raises an error (in Dartium).
I found the article mentioned about it.
What if you have a compute-intensive task to run? To keep your app responsive, you should put the task into its own isolate or worker. Isolates might run in a separate process or thread, depending on the Dart implementation. In 1.0 we don’t expect web apps to support isolates or Dart-language workers. However, you can use the dart:html Worker class to add a JavaScript worker to a Dart web app. https://www.dartlang.org/articles/event-loop/
https://api.dartlang.org/apidocs/channels/stable/dartdoc-viewer/dart:html.Worker
Please anyone tell me if I'm misunderstanding something.

1 comment:

  1. Thanks for sharing your honest experience. When I first took a look at my head shots,
    I wasn’t too thrilled with mine but you’ve given me a new perspective!

    Virtual Edge

    ReplyDelete