|
7 | 7 | import {transformErrorForSerialization} from 'vs/base/common/errors'; |
8 | 8 | import {Disposable} from 'vs/base/common/lifecycle'; |
9 | 9 | import {ErrorCallback, TPromise, ValueCallback} from 'vs/base/common/winjs.base'; |
10 | | -import {IWorker, IWorkerFactory} from './workerClient'; |
11 | 10 | import {ShallowCancelThenPromise} from 'vs/base/common/async'; |
| 11 | +import {isWeb} from 'vs/base/common/platform'; |
12 | 12 |
|
13 | 13 | const INITIALIZE = '$initialize'; |
14 | 14 |
|
| 15 | +export interface IWorker { |
| 16 | + getId():number; |
| 17 | + postMessage(message:string):void; |
| 18 | + dispose():void; |
| 19 | +} |
| 20 | + |
| 21 | +export interface IWorkerCallback { |
| 22 | + (message:string):void; |
| 23 | +} |
| 24 | + |
| 25 | +export interface IWorkerFactory { |
| 26 | + create(moduleId:string, callback:IWorkerCallback, onErrorCallback:(err:any)=>void):IWorker; |
| 27 | +} |
| 28 | + |
| 29 | +let webWorkerWarningLogged = false; |
| 30 | +export function logOnceWebWorkerWarning(err: any): void { |
| 31 | + if (!isWeb) { |
| 32 | + // running tests |
| 33 | + return; |
| 34 | + } |
| 35 | + if (!webWorkerWarningLogged) { |
| 36 | + webWorkerWarningLogged = true; |
| 37 | + console.warn('Could not create web worker(s). Falling back to loading web worker code in main thread, which might cause UI freezes. Please see https://github.com/Microsoft/monaco-editor#faq'); |
| 38 | + } |
| 39 | + console.warn(err.message); |
| 40 | +} |
| 41 | + |
15 | 42 | interface IMessage { |
16 | 43 | vsWorker: number; |
17 | 44 | req?: string; |
@@ -308,7 +335,6 @@ export class SimpleWorkerServer { |
308 | 335 | private initialize(workerId: number, moduleId: string, loaderConfig:any): TPromise<any> { |
309 | 336 | this._protocol.setWorkerId(workerId); |
310 | 337 |
|
311 | | - // TODO@Alex: share this code with workerServer |
312 | 338 | if (loaderConfig) { |
313 | 339 | // Remove 'baseUrl', handling it is beyond scope for now |
314 | 340 | if (typeof loaderConfig.baseUrl !== 'undefined') { |
|
0 commit comments