Refactor event bus and queue system; detect cycles in DI realization and make
Some checks failed
continuous-integration/drone/push Build is failing
Some checks failed
continuous-integration/drone/push Build is failing
This commit is contained in:
28
src/http/kernel/module/ClearRequestEventBusHTTPModule.ts
Normal file
28
src/http/kernel/module/ClearRequestEventBusHTTPModule.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
import {HTTPKernelModule} from '../HTTPKernelModule'
|
||||
import {Inject, Injectable} from '../../../di'
|
||||
import {HTTPKernel} from '../HTTPKernel'
|
||||
import {Request} from '../../lifecycle/Request'
|
||||
import {Bus} from '../../../support/bus'
|
||||
|
||||
/**
|
||||
* HTTP kernel module that creates a request-specific event bus
|
||||
* and injects it into the request container.
|
||||
*/
|
||||
@Injectable()
|
||||
export class ClearRequestEventBusHTTPModule extends HTTPKernelModule {
|
||||
@Inject()
|
||||
protected bus!: Bus
|
||||
|
||||
public static register(kernel: HTTPKernel): void {
|
||||
kernel.register(this).first()
|
||||
}
|
||||
|
||||
public async apply(request: Request): Promise<Request> {
|
||||
const requestBus = request.make<Bus>(Bus)
|
||||
await requestBus.down()
|
||||
|
||||
// FIXME disconnect request bus from global event bus
|
||||
|
||||
return request
|
||||
}
|
||||
}
|
||||
@@ -2,8 +2,7 @@ import {HTTPKernelModule} from '../HTTPKernelModule'
|
||||
import {Inject, Injectable} from '../../../di'
|
||||
import {HTTPKernel} from '../HTTPKernel'
|
||||
import {Request} from '../../lifecycle/Request'
|
||||
import {EventBus} from '../../../event/EventBus'
|
||||
import {PropagatingEventBus} from '../../../event/PropagatingEventBus'
|
||||
import {Bus} from '../../../support/bus'
|
||||
|
||||
/**
|
||||
* HTTP kernel module that creates a request-specific event bus
|
||||
@@ -12,17 +11,18 @@ import {PropagatingEventBus} from '../../../event/PropagatingEventBus'
|
||||
@Injectable()
|
||||
export class InjectRequestEventBusHTTPModule extends HTTPKernelModule {
|
||||
@Inject()
|
||||
protected bus!: EventBus
|
||||
protected bus!: Bus
|
||||
|
||||
public static register(kernel: HTTPKernel): void {
|
||||
kernel.register(this).first()
|
||||
}
|
||||
|
||||
public async apply(request: Request): Promise<Request> {
|
||||
const bus = <PropagatingEventBus> this.make(PropagatingEventBus)
|
||||
bus.connect(this.bus)
|
||||
const requestBus = this.container().makeNew<Bus>(Bus)
|
||||
await requestBus.up()
|
||||
await requestBus.connect(this.bus)
|
||||
|
||||
request.purge(EventBus).registerProducer(EventBus, () => bus)
|
||||
request.purge(Bus).registerProducer(Bus, () => requestBus)
|
||||
return request
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user