formgen/source/logic/ioc/_trait_notification.ts

55 lines
660 B
TypeScript
Raw Permalink Normal View History

2026-09-30 08:38:52 +02:00
namespace formgen.ioc
{
/**
*/
export class trait_notification<type_value>
{
/**
*/
private handlers : Array<type_handler<type_value>>;
/**
*/
public constructor(
handlers : Array<type_handler<type_value>>
)
{
this.handlers = handlers;
}
/**
*/
public listen(
handler : type_handler<type_value>
) : void
{
this.handlers.push(handler);
}
/**
*/
public async notify(
value : type_value
) : Promise<void>
{
return (
Promise.all<void>(
this.handlers.map(
handler => handler(value)
)
)
.then(
() => Promise.resolve<void>(undefined)
)
);
}
}
}