-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
339 additions
and
52 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
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,56 @@ | ||
// Copyright IBM Corp. 2018. All Rights Reserved. | ||
// Node module: @loopback/core | ||
// This file is licensed under the MIT License. | ||
// License text available at https://opensource.org/licenses/MIT | ||
|
||
import { | ||
Constructor, | ||
BindingAddress, | ||
Binding, | ||
BindingScope, | ||
} from '@loopback/context'; | ||
|
||
/** | ||
* Observers to handle life cycle start/stop events | ||
*/ | ||
export interface LifeCycleObserver { | ||
start(): Promise<void> | void; | ||
stop(): Promise<void> | void; | ||
} | ||
|
||
/** | ||
* Test if an object implements LifeCycleObserver | ||
* @param obj An object | ||
*/ | ||
export function isLifeCycleObserver(obj: { | ||
[name: string]: unknown; | ||
}): obj is LifeCycleObserver { | ||
return typeof obj.start === 'function' && typeof obj.stop === 'function'; | ||
} | ||
|
||
/** | ||
* Test if a class implements LifeCycleObserver | ||
* @param ctor A class | ||
*/ | ||
export function isLifeCycleObserverClass( | ||
ctor: Constructor<unknown>, | ||
): ctor is Constructor<LifeCycleObserver> { | ||
return ( | ||
ctor.prototype && | ||
typeof ctor.prototype.start === 'function' && | ||
typeof ctor.prototype.stop === 'function' | ||
); | ||
} | ||
|
||
/** | ||
* Binding tag for life cycle observers | ||
*/ | ||
export const LIFE_CYCLE_OBSERVER_TAG = 'lifeCycleObserver'; | ||
|
||
/** | ||
* Configure the binding as life cycle observer | ||
* @param binding Binding | ||
*/ | ||
export function asLifeCycleObserverBinding<T = unknown>(binding: Binding<T>) { | ||
return binding.tag(LIFE_CYCLE_OBSERVER_TAG).inScope(BindingScope.SINGLETON); | ||
} |
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
Oops, something went wrong.