@@ -13,19 +13,21 @@ import { IStorageService, StorageScope } from 'vs/platform/storage/common/storag
1313import { ipcRenderer as ipc } from 'electron' ;
1414import Event , { Emitter } from 'vs/base/common/event' ;
1515import { IWindowService } from 'vs/platform/windows/common/windows' ;
16+ import { mark } from 'vs/base/common/performance' ;
17+ import { Barrier } from 'vs/workbench/services/extensions/node/barrier' ;
1618
1719export class LifecycleService implements ILifecycleService {
1820
1921 private static readonly _lastShutdownReasonKey = 'lifecyle.lastShutdownReason' ;
2022
2123 public _serviceBrand : any ;
2224
23- private readonly _onDidChangePhase = new Emitter < LifecyclePhase > ( ) ;
2425 private readonly _onWillShutdown = new Emitter < ShutdownEvent > ( ) ;
2526 private readonly _onShutdown = new Emitter < ShutdownReason > ( ) ;
2627 private readonly _startupKind : StartupKind ;
2728
2829 private _phase : LifecyclePhase = LifecyclePhase . Starting ;
30+ private _phaseWhen = new Map < LifecyclePhase , Barrier > ( ) ;
2931
3032 constructor (
3133 @IMessageService private _messageService : IMessageService ,
@@ -50,18 +52,36 @@ export class LifecycleService implements ILifecycleService {
5052 }
5153
5254 public set phase ( value : LifecyclePhase ) {
53- if ( this . _phase !== value ) {
54- this . _phase = value ;
55- this . _onDidChangePhase . fire ( value ) ;
55+ if ( value < this . phase ) {
56+ throw new Error ( 'Lifecycle cannot go backwards' ) ;
57+ }
58+ if ( this . _phase === value ) {
59+ return ;
60+ }
61+
62+ this . _phase = value ;
63+ mark ( `LifecyclePhase/${ LifecyclePhase [ value ] } ` ) ;
64+
65+ if ( this . _phaseWhen . has ( this . _phase ) ) {
66+ this . _phaseWhen . get ( this . _phase ) . open ( ) ;
67+ this . _phaseWhen . delete ( this . _phase ) ;
5668 }
5769 }
5870
59- public get startupKind ( ) : StartupKind {
60- return this . _startupKind ;
71+ public when ( phase : LifecyclePhase ) : Thenable < any > {
72+ if ( phase <= this . _phase ) {
73+ return Promise . resolve ( ) ;
74+ }
75+ let barrier = this . _phaseWhen . get ( phase ) ;
76+ if ( ! barrier ) {
77+ barrier = new Barrier ( ) ;
78+ this . _phaseWhen . set ( phase , barrier ) ;
79+ }
80+ return barrier . wait ( ) ;
6181 }
6282
63- public get onDidChangePhase ( ) : Event < LifecyclePhase > {
64- return this . _onDidChangePhase . event ;
83+ public get startupKind ( ) : StartupKind {
84+ return this . _startupKind ;
6585 }
6686
6787 public get onWillShutdown ( ) : Event < ShutdownEvent > {
0 commit comments