From f1e0fd081d77bf80cf9f83a4995123dab8d1e960 Mon Sep 17 00:00:00 2001 From: Janne Savolainen Date: Wed, 27 Apr 2022 10:45:43 +0300 Subject: [PATCH] Introduce concept of runnable as a way to delegate runs to Open Closed Principle compliant runnables Co-authored-by: Mikko Aspiala Signed-off-by: Janne Savolainen --- .../start-main-application/run-many-for.ts | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 src/main/start-main-application/run-many-for.ts diff --git a/src/main/start-main-application/run-many-for.ts b/src/main/start-main-application/run-many-for.ts new file mode 100644 index 0000000000..10d73e5ea4 --- /dev/null +++ b/src/main/start-main-application/run-many-for.ts @@ -0,0 +1,22 @@ +/** + * Copyright (c) OpenLens Authors. All rights reserved. + * Licensed under MIT License. See LICENSE in root directory for more information. + */ +import type { + DiContainerForInjection, + InjectionToken, +} from "@ogre-tools/injectable"; + +export interface Runnable { + run: (parameter: TParameter) => Promise | void; +} + +export const runManyFor = + (di: DiContainerForInjection) => + >( + injectionToken: InjectionToken, + ) => + async (parameter: Parameters[0]) => + await Promise.all( + di.injectMany(injectionToken).map((runnable) => runnable.run(parameter)), + );