close method

FutureOr<QueryLifecycle> close({
  1. bool force = false,
  2. bool fromManager = false,
})

Closes the query or mutation, or else queues it for closing.

To preserve Mutation side effects, close checks the lifecycle, queuing the stream for closing if sideEffectsArePending. You can override this check with force: true.

Returns a FutureOr of the resultant lifecycle, either QueryLifecycle.sideEffectsBlocking or QueryLifecycle.closed

Implementation

FutureOr<QueryLifecycle> close({
  bool force = false,
  bool fromManager = false,
}) async {
  if (lifecycle == QueryLifecycle.sideEffectsPending && !force) {
    lifecycle = QueryLifecycle.sideEffectsBlocking;
    // stop closing because we're waiting on something
    return lifecycle;
  }

  // `fromManager` is used by the query manager when it wants to close a query to avoid infinite loops
  if (!fromManager) {
    queryManager.closeQuery(this, fromQuery: true);
  }

  stopPolling();

  await controller.close();

  lifecycle = QueryLifecycle.closed;
  return QueryLifecycle.closed;
}