Skip to content
This repository has been archived by the owner on Oct 23, 2021. It is now read-only.

sp core library.servicescope.whenfinished

John Nguyen edited this page Apr 22, 2021 · 2 revisions

Home > @microsoft/sp-core-library > ServiceScope > whenFinished

ServiceScope.whenFinished() method

Defer an operation until after ServiceScope.finish() has completed.

Signature:

whenFinished(callback: () => void): void;

Parameters

Parameter Type Description
callback () => void A block of code that needs to call ServiceScope.consume()

Returns:

void

Remarks

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().

Clone this wiki locally