1// Copyright (C) MongoDB, Inc. 2017-present. 2// 3// Licensed under the Apache License, Version 2.0 (the "License"); you may 4// not use this file except in compliance with the License. You may obtain 5// a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 6 7package unified 8 9import "context" 10 11func executeIterateUntilDocumentOrError(ctx context.Context, operation *Operation) (*OperationResult, error) { 12 stream, err := Entities(ctx).ChangeStream(operation.Object) 13 if err != nil { 14 return nil, err 15 } 16 17 for { 18 if stream.TryNext(ctx) { 19 return NewDocumentResult(stream.Current, nil), nil 20 } 21 if stream.Err() != nil { 22 return NewErrorResult(stream.Err()), nil 23 } 24 } 25} 26