Continuation Example

Here’s the markup for a component that calls a continuation with the wire service and imperatively after you click a button.

The HTML contains a button that triggers an imperative call to the continuation. We see more when we look at the JavaScript file next.

Here's the component's JavaScript file.

This code uses a new import syntax.

This import statement tells the framework that we're calling an Apex method that can return a continuation. If the startRequest Apex method returns a Continuation object, the method must be annotated with @AuraEnabled(continuation=true).

The component uses the wire service to call the startRequest Apex method. The wire service delegates control flow to the Lightning Web Components engine. When data becomes available from the wire adapter after the continuation executes, the template displays the results. You can use the wire service because startRequest() is annotated with @AuraEnabled(cacheable=true) in the Apex class.

Since continuations make long-running requests, you might prefer to control when the continuation execution starts by making an imperative call instead of using the wire service. This component uses the wire service and an imperative call. The wire service calls the continuation and caches the result. When you click the button to make the imperative call to the same Apex method, the cached results are returned and displayed in the template.

See Also