Skip to content

Commit

Permalink
fix: make start/stop methods optional
Browse files Browse the repository at this point in the history
A thing that is stoppable might not need to be startable so make
the methods optional.
  • Loading branch information
achingbrain committed Nov 2, 2024
1 parent ad5cfd6 commit c150be4
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions packages/interface/src/startable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export interface Startable {
*
* It should not assume that any other components have been started.
*/
start(): void | Promise<void>
start?(): void | Promise<void>

/**
* If implemented, this method will be invoked after the start method.
Expand All @@ -35,7 +35,7 @@ export interface Startable {
*
* It should not assume any other components are running when it is called.
*/
stop(): void | Promise<void>
stop?(): void | Promise<void>

/**
* If implemented, this method will be invoked after the stop method.
Expand Down Expand Up @@ -68,7 +68,9 @@ export async function start (...objs: any[]): Promise<void> {

await Promise.all(
startables.map(async s => {
await s.start()
if (s.start != null) {
await s.start()
}
})
)

Expand Down Expand Up @@ -100,7 +102,9 @@ export async function stop (...objs: any[]): Promise<void> {

await Promise.all(
startables.map(async s => {
await s.stop()
if (s.stop != null) {
await s.stop()
}
})
)

Expand Down

0 comments on commit c150be4

Please sign in to comment.