Skip to content

Commit

Permalink
feat(common): add IAsyncProvider interface definition
Browse files Browse the repository at this point in the history
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 <peter.somogyvari@accenture.com>
  • Loading branch information
petermetz committed Dec 1, 2020
1 parent 51af78d commit 81ec545
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
12 changes: 12 additions & 0 deletions packages/cactus-common/src/main/typescript/i-async-provider.ts
Original file line number Diff line number Diff line change
@@ -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<T> {
/**
* Obtains the value/object meant to be provided by this `IAsyncProvider`
* implementation.
*/
get(): Promise<T>;
}
1 change: 1 addition & 0 deletions packages/cactus-common/src/main/typescript/public-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

0 comments on commit 81ec545

Please sign in to comment.