2015-07-10 16:09:18 -07:00
|
|
|
library angular2.src.web_workers.worker;
|
|
|
|
|
2015-08-17 10:28:47 -07:00
|
|
|
import "package:angular2/src/web-workers/shared/isolate_message_bus.dart";
|
2015-07-10 16:09:18 -07:00
|
|
|
import "package:angular2/src/web-workers/worker/application_common.dart"
|
2015-08-07 13:17:54 -07:00
|
|
|
show bootstrapWebWorkerCommon;
|
2015-07-10 16:09:18 -07:00
|
|
|
import "package:angular2/src/facade/async.dart" show Future;
|
|
|
|
import "package:angular2/src/core/application.dart" show ApplicationRef;
|
|
|
|
import "package:angular2/src/facade/lang.dart" show Type, BaseException;
|
|
|
|
import "dart:isolate";
|
|
|
|
import "dart:async";
|
2015-07-10 16:09:18 -07:00
|
|
|
import 'dart:core';
|
2015-07-10 16:09:18 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Bootstrapping a Webworker Application
|
2015-07-10 16:09:18 -07:00
|
|
|
*
|
2015-07-10 16:09:18 -07:00
|
|
|
* You instantiate the application side by calling bootstrapWebworker from your webworker index
|
|
|
|
* script.
|
|
|
|
* You must supply a SendPort for communicating with the UI side in order to instantiate
|
|
|
|
* the application.
|
|
|
|
* Other than the SendPort you can call bootstrapWebworker() exactly as you would call
|
|
|
|
* bootstrap() in a regular Angular application
|
|
|
|
* See the bootstrap() docs for more details.
|
|
|
|
*/
|
2015-08-07 13:17:54 -07:00
|
|
|
Future<ApplicationRef> bootstrapWebWorker(
|
2015-07-10 16:09:18 -07:00
|
|
|
SendPort replyTo, Type appComponentType,
|
2015-07-10 16:09:18 -07:00
|
|
|
[List<dynamic> componentInjectableBindings = null]) {
|
|
|
|
ReceivePort rPort = new ReceivePort();
|
2015-08-17 10:28:47 -07:00
|
|
|
var sink = new WebWorkerMessageBusSink(replyTo, rPort);
|
|
|
|
var source = new IsolateMessageBusSource(rPort);
|
|
|
|
IsolateMessageBus bus = new IsolateMessageBus(sink, source);
|
2015-08-07 13:17:54 -07:00
|
|
|
return bootstrapWebWorkerCommon(
|
2015-07-27 17:26:28 -07:00
|
|
|
appComponentType, bus, componentInjectableBindings);
|
2015-07-10 16:09:18 -07:00
|
|
|
}
|
|
|
|
|
2015-08-17 10:28:47 -07:00
|
|
|
class WebWorkerMessageBusSink extends IsolateMessageBusSink {
|
|
|
|
WebWorkerMessageBusSink(SendPort sPort, ReceivePort rPort) : super(sPort) {
|
|
|
|
sPort.send(rPort.sendPort);
|
2015-07-10 16:09:18 -07:00
|
|
|
}
|
|
|
|
}
|