Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
feat(core): abilities can be initialised and discarded automatically
Useful when your custom ability needs to perform some asynchronous setup or tear down of the resources it uses. See examples at https://serenity-js.org/modules/core/class/src/screenplay/Ability.ts~Ability.html Enables #563
- Loading branch information
Showing
7 changed files
with
207 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/** | ||
* @desc | ||
* An interface to be implemented by any {@link Ability} that needs to initialise | ||
* the resources it uses (i.e. establish a database connection). | ||
* | ||
* The {@link initialise} method is invoked when {@link Actor#attemptsTo} is called, | ||
* but only when {@link isInitialised} returns false. | ||
* | ||
* @public | ||
*/ | ||
export interface Initialisable { | ||
|
||
/** | ||
* @desc | ||
* Initialises the ability. Invoked when {@link Actor#attemptsTo} is called, | ||
* but only when {@link isInitialised} returns false. | ||
* | ||
* Make sure to implement {@link isInitialised} so that it returns `true` | ||
* when the ability has been successfully initialised. | ||
* | ||
* @returns {Promise<void> | void} | ||
*/ | ||
initialise(): Promise<void> | void; | ||
|
||
/** | ||
* @desc | ||
* Whether or not a given ability has been initialised already | ||
* and should not be initialised again. | ||
* | ||
* @returns {boolean} | ||
*/ | ||
isInitialised(): boolean; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters