Skip to content

Commit 724a6d4

Browse files
fix: correct rebase errors
1 parent 07c403d commit 724a6d4

File tree

3 files changed

+28
-30
lines changed

3 files changed

+28
-30
lines changed

src/container-instance.class.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import { ServiceMetadata } from './interfaces/service-metadata.interface.';
88
import { AsyncInitializedService } from './types/AsyncInitializedService';
99
import { MissingInitializedPromiseError } from './error/MissingInitializedPromiseError';
1010

11-
1211
/**
1312
* TypeDI can have multiple containers.
1413
* One container is ContainerInstance.
@@ -122,7 +121,7 @@ export class ContainerInstance {
122121
* Like get, but returns a promise of a service that recursively resolves async properties.
123122
* Used when service defined with asyncInitialization: true flag.
124123
*/
125-
getAsync<T>(type: ObjectType<T>): Promise<T>;
124+
getAsync<T>(type: Constructable<T>): Promise<T>;
126125

127126
/**
128127
* Like get, but returns a promise of a service that recursively resolves async properties.
@@ -498,9 +497,9 @@ export class ContainerInstance {
498497
if (type) this.applyPropertyHandlers(type, value);
499498

500499
if (value instanceof AsyncInitializedService || service.asyncInitialization) {
501-
return new Promise((resolve) => {
500+
return new Promise(resolve => {
502501
if (!(value.initialized instanceof Promise) && service.asyncInitialization) {
503-
throw new MissingInitializedPromiseError(service.value);
502+
throw new MissingInitializedPromiseError(service.value);
504503
}
505504

506505
value.initialized.then(() => resolve(value));

src/container.class.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import { Constructable } from './types/constructable.type';
55
import { ServiceIdentifier } from './types/service-identifier.type';
66
import { ServiceMetadata } from './interfaces/service-metadata.interface.';
77

8-
98
/**
109
* Service container.
1110
*/
@@ -110,7 +109,7 @@ export class Container {
110109
* Like get, but returns a promise of a service that recursively resolves async properties.
111110
* Used when service defined with asyncInitialization: true flag.
112111
*/
113-
static getAsync<T>(type: ObjectType<T>): Promise<T>;
112+
static getAsync<T>(type: Constructable<T>): Promise<T>;
114113

115114
/**
116115
* Like get, but returns a promise of a service that recursively resolves async properties.

test/decorators/Service.spec.ts

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -172,35 +172,35 @@ describe('Service Decorator', function () {
172172
});
173173

174174
expect(Container.get(TestService)).toBe('TEST_STRING');
175+
});
176+
177+
it('should support services with asynchronous initialization', async function () {
178+
@Service({ asyncInitialization: true })
179+
class Engine {
180+
ignition: string = 'off';
181+
initialized: Promise<any>;
175182

176-
it('should support services with asynchronous initialization', async function () {
177-
@Service({ asyncInitialization: true })
178-
class Engine {
179-
ignition: string = 'off';
180-
initialized: Promise<any>;
181-
182-
constructor() {
183-
this.initialized = this.initialize();
184-
}
185-
186-
protected initialize() {
187-
return new Promise(resolve => {
188-
setTimeout(() => {
189-
this.ignition = 'running';
190-
resolve();
191-
}, 300);
192-
});
193-
}
183+
constructor() {
184+
this.initialized = this.initialize();
194185
}
195186

196-
@Service()
197-
class Car {
198-
constructor(public engine: Engine) {}
187+
protected initialize() {
188+
return new Promise(resolve => {
189+
setTimeout(() => {
190+
this.ignition = 'running';
191+
resolve();
192+
}, 300);
193+
});
199194
}
195+
}
196+
197+
@Service()
198+
class Car {
199+
constructor(public engine: Engine) {}
200+
}
200201

201-
const car = await Container.getAsync<Car>(Car);
202+
const car = await Container.getAsync<Car>(Car);
202203

203-
expect(car.engine.ignition).toEqual('running');
204-
});
204+
expect(car.engine.ignition).toEqual('running');
205205
});
206206
});

0 commit comments

Comments
 (0)