File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -485,4 +485,38 @@ export function createQueuedSender(childProcess: ChildProcess | NodeJS.Process):
485485 } ;
486486
487487 return { send } ;
488- }
488+ }
489+
490+
491+ export interface IEnv {
492+ addDelayedEnvironment ( promise : TPromise < typeof process . env > ) : any ;
493+ ready : TPromise < void > ;
494+ }
495+
496+ export const env : IEnv = new class {
497+
498+ private _promises : TPromise < any > [ ] = [ ] ;
499+
500+ addDelayedEnvironment ( promise : TPromise < typeof process . env > ) : any {
501+ const p = TPromise . wrap ( promise ) . then ( env => {
502+ // mixin new env
503+ Objects . mixin ( process . env , env , true ) ;
504+ } ) ;
505+ this . _promises . push ( p ) ;
506+ const remove = ( ) => {
507+ const idx = this . _promises . indexOf ( p ) ;
508+ if ( idx >= 0 ) {
509+ this . _promises . splice ( idx , 1 ) ;
510+ }
511+ } ;
512+ p . then ( remove , remove ) ;
513+ }
514+
515+ get ready ( ) : TPromise < void > {
516+ if ( this . _promises . length === 0 ) {
517+ return TPromise . as ( undefined ) ;
518+ } else {
519+ return TPromise . join ( this . _promises ) . then ( ( ) => this . ready ) ;
520+ }
521+ }
522+ } ;
Original file line number Diff line number Diff line change @@ -9,6 +9,7 @@ import * as assert from 'assert';
99import * as cp from 'child_process' ;
1010import * as objects from 'vs/base/common/objects' ;
1111import * as platform from 'vs/base/common/platform' ;
12+ import { TPromise } from 'vs/base/common/winjs.base' ;
1213import URI from 'vs/base/common/uri' ;
1314import processes = require( 'vs/base/node/processes' ) ;
1415
@@ -82,4 +83,17 @@ suite('Processes', () => {
8283 }
8384 } ) ;
8485 } ) ;
85- } ) ;
86+
87+ test ( 'env, ready by default' , function ( ) {
88+ return processes . env . ready . then ( ( ) => {
89+ assert . ok ( true ) ;
90+ } ) ;
91+ } ) ;
92+
93+ test ( 'env, delayed' , function ( ) {
94+ processes . env . addDelayedEnvironment ( TPromise . as ( { foo : 1 } ) ) ;
95+ return processes . env . ready . then ( ( ) => {
96+ assert . equal ( process . env . foo , 1 ) ;
97+ } ) ;
98+ } ) ;
99+ } ) ;
You can’t perform that action at this time.
0 commit comments