HttpRequest from isolate

189 views
Skip to first unread message

Michael Hendricks

unread,
Sep 7, 2012, 2:18:22 PM9/7/12
to General Dart Discussion
The following code crashes Dartium ("Aw, Snap") because of "new HttpRequest()" in iso().

#import('dart:isolate');
#import('dart:html');

void main() {
  spawnFunction(iso).send('ping', port.toSendPort());
  port.receive((msg, _) => print('pong: $msg'));
}

iso () {
  port.receive((msg, reply) {
    var req = new HttpRequest();
    reply.send('responding');
  });
}

How does one make an HTTP request from an isolate in the browser?  I'd like to do this in the following use cases:
  • running untrusted code in the browser (eg, custom web app hooks written in Dart)
  • expensive processing of web data (eg, generate encryption keys from random.org data)
  • run same isolate code in browser and server
  • isolates for structural clarity (eg, one isolate per activity)
None of these isolates want access to the DOM, so DOM isolates (issue 3050) seem like overkill.  Maybe that's the best way available.

Suggestions?

-- 
Michael

John Messerly

unread,
Sep 7, 2012, 2:47:44 PM9/7/12
to mi...@dartlang.org
On Fri, Sep 7, 2012 at 11:18 AM, Michael Hendricks <mic...@ndrix.org> wrote:
The following code crashes Dartium ("Aw, Snap") because of "new HttpRequest()" in iso().

#import('dart:isolate');
#import('dart:html');

void main() {
  spawnFunction(iso).send('ping', port.toSendPort());
  port.receive((msg, _) => print('pong: $msg'));
}

iso () {
  port.receive((msg, reply) {
    var req = new HttpRequest();
    reply.send('responding');
  });
}

I filed the crash as http://dartbug.com/4994

 
How does one make an HTTP request from an isolate in the browser?  I'd like to do this in the following use cases:

If it works in JS web workers, it should work from an isolate.

Michael Hendricks

unread,
Sep 7, 2012, 4:01:40 PM9/7/12
to mi...@dartlang.org
Thanks John.  It looks like the same thing happens with Timer.  I've filed that one as http://code.google.com/p/dart/issues/detail?id=4997

-- 
Michael


--
Consider asking HOWTO questions at Stack Overflow: http://stackoverflow.com/tags/dart
 
 

Peter Jakobs

unread,
Sep 8, 2012, 8:51:22 AM9/8/12
to mi...@dartlang.org
An isolate is not the same thing as a Worker, note that you can spawn an webworker with dart aswell (even with a JS script inside).

The plan is, from what I could gather over the last month, that isolates can do everything workers can do. In a past dartisian episode they told us that isolates is one of the least refactored thing in dart at the moment.

In the end, isolates should be able to spawn workers aswell and support zero-copy sending of TypedArrays. (beside access to the File API and the navigator)

Currently, if you want to use HttpRequests and want to use dart isolates spawned from functions you need to implement some infrastructur so that your non-dom isolates can make a request to a dom isolates that does a HttpRequest and sends the received data to the isolate that requested the data.
Reply all
Reply to author
Forward
0 new messages