-
Notifications
You must be signed in to change notification settings - Fork 5
sp core library.servicescope.whenfinished
Home > @microsoft/sp-core-library > ServiceScope > whenFinished
Defer an operation until after ServiceScope.finish() has completed.
Signature:
whenFinished(callback: () => void): void;
Parameter | Type | Description |
---|---|---|
callback | () => void | A block of code that needs to call ServiceScope.consume() |
Returns:
void
It is an error to call ServiceScope.consume() before finish() has been called. The most reliable way to protect your component against this error is to perform the consume() calls inside a whenFinished() callback. If the service scope is already finished, then the callback will be executed immediately; otherwise, it will be executed later when the scope is finished.
NOTE: This is not an asynchronous callback. ServiceScope initialization is typically inexpensive and short lived. However, the control flow often threads through numerous constructors and base classes, which can be simplified using whenFinished().