From 81ec545701409fa626ce82d4e8513e0d78db9e30 Mon Sep 17 00:00:00 2001 From: Peter Somogyvari Date: Thu, 12 Nov 2020 12:38:29 -0800 Subject: [PATCH] feat(common): add IAsyncProvider interface definition This is a commonly reusable interface that objects/classes can choose to implement to express that they have the ability to provide a certain value. Helps a lot while authoring methods that must be able to accept injected providers as parameters for example in order to allow them to be customizable without doing an actual source code rewrite of the functions itself. Signed-off-by: Peter Somogyvari --- .../src/main/typescript/i-async-provider.ts | 12 ++++++++++++ .../cactus-common/src/main/typescript/public-api.ts | 1 + 2 files changed, 13 insertions(+) create mode 100644 packages/cactus-common/src/main/typescript/i-async-provider.ts diff --git a/packages/cactus-common/src/main/typescript/i-async-provider.ts b/packages/cactus-common/src/main/typescript/i-async-provider.ts new file mode 100644 index 0000000000..d6f3181990 --- /dev/null +++ b/packages/cactus-common/src/main/typescript/i-async-provider.ts @@ -0,0 +1,12 @@ +/** + * A generic interface to be implemented by objects/classes that want to express + * their ability of returning a certain type of object or value in an async + * manner (e.g. by returning a Promise of what is actually being provided). + */ +export interface IAsyncProvider { + /** + * Obtains the value/object meant to be provided by this `IAsyncProvider` + * implementation. + */ + get(): Promise; +} diff --git a/packages/cactus-common/src/main/typescript/public-api.ts b/packages/cactus-common/src/main/typescript/public-api.ts index 436bd1439f..168497b6af 100755 --- a/packages/cactus-common/src/main/typescript/public-api.ts +++ b/packages/cactus-common/src/main/typescript/public-api.ts @@ -18,3 +18,4 @@ export { export { ISignerKeyPair } from "./signer-key-pair"; export { Secp256k1Keys } from "./secp256k1-keys"; export { KeyFormat, KeyConverter } from "./key-converter"; +export { IAsyncProvider } from "./i-async-provider";