2015-07-10 16:09:18 -07:00
|
|
|
import {
|
2015-08-17 10:28:47 -07:00
|
|
|
PostMessageBus,
|
|
|
|
PostMessageBusSink,
|
|
|
|
PostMessageBusSource
|
|
|
|
} from 'angular2/src/web-workers/shared/post_message_bus';
|
|
|
|
import {MessageBus} from 'angular2/src/web-workers/shared/message_bus';
|
2015-07-10 16:09:18 -07:00
|
|
|
import {BaseException} from "angular2/src/facade/lang";
|
2015-07-10 16:09:18 -07:00
|
|
|
import {bootstrapUICommon} from "angular2/src/web-workers/ui/impl";
|
2015-07-10 16:09:18 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Bootstrapping a WebWorker
|
|
|
|
*
|
|
|
|
* You instantiate a WebWorker application by calling bootstrap with the URI of your worker's index
|
|
|
|
* script
|
|
|
|
* Note: The WebWorker script must call bootstrapWebworker once it is set up to complete the
|
|
|
|
* bootstrapping process
|
|
|
|
*/
|
2015-07-31 10:33:22 -07:00
|
|
|
export function bootstrap(uri: string): MessageBus {
|
2015-08-07 13:17:54 -07:00
|
|
|
var messageBus = spawnWebWorker(uri);
|
2015-07-10 16:09:18 -07:00
|
|
|
bootstrapUICommon(messageBus);
|
2015-07-31 10:33:22 -07:00
|
|
|
return messageBus;
|
2015-07-10 16:09:18 -07:00
|
|
|
}
|
|
|
|
|
2015-08-07 13:17:54 -07:00
|
|
|
export function spawnWebWorker(uri: string): MessageBus {
|
|
|
|
var webWorker: Worker = new Worker(uri);
|
2015-08-17 10:28:47 -07:00
|
|
|
var sink = new PostMessageBusSink(webWorker);
|
|
|
|
var source = new PostMessageBusSource(webWorker);
|
|
|
|
return new PostMessageBus(sink, source);
|
2015-07-10 16:09:18 -07:00
|
|
|
}
|