Skip to content

Commit

Permalink
fix: correct rebase errors
Browse files Browse the repository at this point in the history
  • Loading branch information
NoNameProvided committed Jan 9, 2021
1 parent 07c403d commit 724a6d4
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 30 deletions.
7 changes: 3 additions & 4 deletions src/container-instance.class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { ServiceMetadata } from './interfaces/service-metadata.interface.';
import { AsyncInitializedService } from './types/AsyncInitializedService';
import { MissingInitializedPromiseError } from './error/MissingInitializedPromiseError';


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

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

if (value instanceof AsyncInitializedService || service.asyncInitialization) {
return new Promise((resolve) => {
return new Promise(resolve => {
if (!(value.initialized instanceof Promise) && service.asyncInitialization) {
throw new MissingInitializedPromiseError(service.value);
throw new MissingInitializedPromiseError(service.value);
}

value.initialized.then(() => resolve(value));
Expand Down
3 changes: 1 addition & 2 deletions src/container.class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { Constructable } from './types/constructable.type';
import { ServiceIdentifier } from './types/service-identifier.type';
import { ServiceMetadata } from './interfaces/service-metadata.interface.';


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

/**
* Like get, but returns a promise of a service that recursively resolves async properties.
Expand Down
48 changes: 24 additions & 24 deletions test/decorators/Service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,35 +172,35 @@ describe('Service Decorator', function () {
});

expect(Container.get(TestService)).toBe('TEST_STRING');
});

it('should support services with asynchronous initialization', async function () {
@Service({ asyncInitialization: true })
class Engine {
ignition: string = 'off';
initialized: Promise<any>;

it('should support services with asynchronous initialization', async function () {
@Service({ asyncInitialization: true })
class Engine {
ignition: string = 'off';
initialized: Promise<any>;

constructor() {
this.initialized = this.initialize();
}

protected initialize() {
return new Promise(resolve => {
setTimeout(() => {
this.ignition = 'running';
resolve();
}, 300);
});
}
constructor() {
this.initialized = this.initialize();
}

@Service()
class Car {
constructor(public engine: Engine) {}
protected initialize() {
return new Promise(resolve => {
setTimeout(() => {
this.ignition = 'running';
resolve();
}, 300);
});
}
}

@Service()
class Car {
constructor(public engine: Engine) {}
}

const car = await Container.getAsync<Car>(Car);
const car = await Container.getAsync<Car>(Car);

expect(car.engine.ignition).toEqual('running');
});
expect(car.engine.ignition).toEqual('running');
});
});

0 comments on commit 724a6d4

Please sign in to comment.