Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 20 additions & 4 deletions Sources/MongoSwift/ChangeStream.swift
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,19 @@ public class ChangeStream<T: Codable>: CursorProtocol {
}
}

/// Indicates whether this change stream has the potential to return more data.
/**
* Indicates whether this change stream has the potential to return more data.
*
* This change stream will be dead after `next` returns `nil`, but it may still be alive after `tryNext` returns
* `nil`.
*
* After either of `next` or `tryNext` return a non-`DecodingError` error, this change stream will be dead. It may
* still be alive after either returns a `DecodingError`, however.
*
* - Warning:
* If this change stream is alive when it goes out of scope, it will leak resources. To ensure it is dead
* before it leaves scope, invoke `ChangeStream.kill(...)` on it.
*/
public func isAlive() -> EventLoopFuture<Bool> {
self.client.operationExecutor.execute {
self.wrappedCursor.isAlive
Expand Down Expand Up @@ -234,9 +246,13 @@ public class ChangeStream<T: Codable>: CursorProtocol {
/**
* Kill this change stream.
*
* This method MUST be called before this change stream goes out of scope to prevent leaking resources.
* This method may be called even if there are unresolved futures created from other `ChangeStream` methods.
* This method will have no effect if the change stream is already dead.
* This method MAY be called even if there are unresolved futures created from other `ChangeStream` methods.
*
* This method MAY be called if the change stream is already dead. It will have no effect.
*
* - Warning:
* If this change stream is alive when it goes out of scope, it will leak resources. To ensure it
* is dead before it leaves scope, invoke this method.
*
* - Returns:
* An `EventLoopFuture` that evaluates when the change stream has completed closing. This future should not fail.
Expand Down
12 changes: 12 additions & 0 deletions Sources/MongoSwift/MongoClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,10 @@ public class MongoClient {
* - options: An optional `ChangeStreamOptions` to use when constructing the change stream.
* - session: An optional `ClientSession` to use with this change stream.
*
* - Warning:
* If the returned change stream is alive when it goes out of scope, it will leak resources. To ensure the
* change stream is dead before it leaves scope, invoke `ChangeStream.kill(...)` on it.
*
* - Returns:
* An `EventLoopFuture<ChangeStream>`. On success, contains a `ChangeStream` watching all collections in this
* deployment.
Expand Down Expand Up @@ -512,6 +516,10 @@ public class MongoClient {
* - withFullDocumentType: The type that the `fullDocument` field of the emitted `ChangeStreamEvent`s will be
* decoded to.
*
* - Warning:
* If the returned change stream is alive when it goes out of scope, it will leak resources. To ensure the
* change stream is dead before it leaves scope, invoke `ChangeStream.kill(...)` on it.
*
* - Returns:
* An `EventLoopFuture<ChangeStream>`. On success, contains a `ChangeStream` watching all collections in this
* deployment.
Expand Down Expand Up @@ -554,6 +562,10 @@ public class MongoClient {
* - withEventType: The type that the entire change stream response will be decoded to and that will be returned
* when iterating through the change stream.
*
* - Warning:
* If the returned change stream is alive when it goes out of scope, it will leak resources. To ensure the
* change stream is dead before it leaves scope, invoke `ChangeStream.kill(...)` on it.
*
* - Returns:
* An `EventLoopFuture<ChangeStream>`. On success, contains a `ChangeStream` watching all collections in this
* deployment.
Expand Down
12 changes: 12 additions & 0 deletions Sources/MongoSwift/MongoCollection+ChangeStreams.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ extension MongoCollection {
* - options: An optional `ChangeStreamOptions` to use when constructing the change stream.
* - session: An optional `ClientSession` to use with this change stream.
*
* - Warning:
* If the returned change stream is alive when it goes out of scope, it will leak resources. To ensure the
* change stream is dead before it leaves scope, invoke `ChangeStream.kill(...)` on it.
*
* - Returns:
* An `EventLoopFuture<ChangeStream>`. On success, contains a `ChangeStream` watching this collection.
*
Expand Down Expand Up @@ -46,6 +50,10 @@ extension MongoCollection {
* - withFullDocumentType: The type that the `fullDocument` field of the emitted `ChangeStreamEvent`s will be
* decoded to.
*
* - Warning:
* If the returned change stream is alive when it goes out of scope, it will leak resources. To ensure the
* change stream is dead before it leaves scope, invoke `ChangeStream.kill(...)` on it.
*
* - Returns:
* An `EventLoopFuture<ChangeStream>`. On success, contains a `ChangeStream` watching this collection.
*
Expand Down Expand Up @@ -85,6 +93,10 @@ extension MongoCollection {
* - withEventType: The type that the entire change stream response will be decoded to and that will be returned
* when iterating through the change stream.
*
* - Warning:
* If the returned change stream is alive when it goes out of scope, it will leak resources. To ensure the
* change stream is dead before it leaves scope, invoke `ChangeStream.kill(...)` on it.
*
* - Returns:
* An `EventLoopFuture<ChangeStream>`. On success, contains a `ChangeStream` watching this collection.
*
Expand Down
4 changes: 4 additions & 0 deletions Sources/MongoSwift/MongoCollection+Indexes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,10 @@ extension MongoCollection {
* - Parameters:
* - session: Optional `ClientSession` to use when executing this command
*
* - Warning:
* If the returned cursor is alive when it goes out of scope, it will leak resources. To ensure the
* cursor is dead before it leaves scope, invoke `MongoCursor.kill(...)` on it.
*
* - Returns:
* An `EventLoopFuture<MongoCursor<IndexModel>>`. On success, contains a cursor over the indexes.
*
Expand Down
8 changes: 8 additions & 0 deletions Sources/MongoSwift/MongoCollection+Read.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ extension MongoCollection {
/**
* Finds the documents in this collection which match the provided filter.
*
* - Warning:
* If the returned cursor is alive when it goes out of scope, it will leak resources. To ensure the cursor
* is dead before it leaves scope, invoke `MongoCursor.kill(...)` on it.
*
* - Parameters:
* - filter: A `BSONDocument` that should match the query
* - options: Optional `FindOptions` to use when executing the command
Expand Down Expand Up @@ -66,6 +70,10 @@ extension MongoCollection {
* - options: Optional `AggregateOptions` to use when executing the command
* - session: Optional `ClientSession` to use when executing this command
*
* - Warning:
* If the returned cursor is alive when it goes out of scope, it will leak resources. To ensure the cursor
* is dead before it leaves scope, invoke `MongoCursor.kill(...)` on it.
*
* - Returns:
* An `EventLoopFuture<MongoCursor<CollectionType>`. On success, contains a cursor over the resulting documents.
*
Expand Down
21 changes: 17 additions & 4 deletions Sources/MongoSwift/MongoCursor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,17 @@ public class MongoCursor<T: Codable>: CursorProtocol {
* This method is mainly useful if this cursor is tailable, since in that case `tryNext` may return more results
* even after returning `nil`.
*
* If this cursor is non-tailable, it will always be dead as soon as either `tryNext` returns `nil` or an error.
* If this cursor is non-tailable, it will always be dead after either `tryNext` returns `nil` or a
* non-`DecodingError` error.
*
* This cursor will be dead as soon as `next` returns `nil` or an error, regardless of the `MongoCursorType`.
* This cursor will be dead after `next` returns `nil` or a non-`DecodingError` error, regardless of the
* `MongoCursorType`.
*
* This cursor may still be alive after `next` or `tryNext` returns a `DecodingError`.
*
* - Warning:
* If this cursor is alive when it goes out of scope, it will leak resources. To ensure it is dead before it
* leaves scope, invoke `MongoCursor.kill(...)` on it.
*/
public func isAlive() -> EventLoopFuture<Bool> {
self.client.operationExecutor.execute {
Expand Down Expand Up @@ -231,8 +239,13 @@ public class MongoCursor<T: Codable>: CursorProtocol {
/**
* Kill this cursor.
*
* This method MUST be called before this cursor goes out of scope to prevent leaking resources.
* This method may be called even if there are unresolved futures created from other `MongoCursor` methods.
* This method MAY be called even if there are unresolved futures created from other `MongoCursor` methods.
*
* This method MAY be called if the cursor is already dead. It will have no effect.
*
* - Warning:
* If this cursor is alive when it goes out of scope, it will leak resources. To ensure it
* is dead before it leaves scope, invoke this method.
*
* - Returns:
* An `EventLoopFuture` that evaluates when the cursor has completed closing. This future should not fail.
Expand Down
16 changes: 16 additions & 0 deletions Sources/MongoSwift/MongoDatabase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,10 @@ public struct MongoDatabase {
* - options: Optional `ListCollectionsOptions` to use when executing this command
* - session: Optional `ClientSession` to use when executing this command
*
* - Warning:
* If the returned cursor is alive when it goes out of scope, it will leak resources. To ensure the cursor
* is dead before it leaves scope, invoke `MongoCursor.kill(...)` on it.
*
* - Returns:
* An `EventLoopFuture<MongoCursor<CollectionSpecification>>` containing a cursor over the collections.
*
Expand Down Expand Up @@ -352,6 +356,10 @@ public struct MongoDatabase {
* - options: An optional `ChangeStreamOptions` to use when constructing the change stream.
* - session: An optional `ClientSession` to use with this change stream.
*
* - Warning:
* If the returned change stream is alive when it goes out of scope, it will leak resources. To ensure the
* change stream is dead before it leaves scope, invoke `ChangeStream.kill(...)` on it.
*
* - Returns:
* An `EventLoopFuture<ChangeStream>`. On success, contains a `ChangeStream` watching all collections in this
* database.
Expand Down Expand Up @@ -389,6 +397,10 @@ public struct MongoDatabase {
* - withFullDocumentType: The type that the `fullDocument` field of the emitted `ChangeStreamEvent`s will be
* decoded to.
*
* - Warning:
* If the returned change stream is alive when it goes out of scope, it will leak resources. To ensure the
* change stream is dead before it leaves scope, invoke `ChangeStream.kill(...)` on it.
*
* - Returns:
* An `EventLoopFuture<ChangeStream>`. On success, contains a `ChangeStream` watching all collections in this
* database.
Expand Down Expand Up @@ -431,6 +443,10 @@ public struct MongoDatabase {
* - withEventType: The type that the entire change stream response will be decoded to and that will be returned
* when iterating through the change stream.
*
* - Warning:
* If the returned change stream is alive when it goes out of scope, it will leak resources. To ensure the
* change stream is dead before it leaves scope, invoke `ChangeStream.kill(...)` on it.
*
* - Returns:
* An `EventLoopFuture<ChangeStream>`. On success, contains a `ChangeStream` watching all collections in this
* database.
Expand Down
7 changes: 5 additions & 2 deletions Sources/MongoSwiftSync/ChangeStream.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,11 @@ public class ChangeStream<T: Codable>: CursorProtocol {
/**
* Indicates whether this change stream has the potential to return more data.
*
* This change stream will be dead if `next` returns `nil` or an error. It will also be dead if `tryNext` returns
* an error, but will still be alive if `tryNext` returns `nil`.
* This change stream will be dead after `next` returns `nil`, but it may still be alive after `tryNext` returns
* `nil`.
*
* After either of `next` or `tryNext` return a non-`DecodingError` error, this change stream will be dead. It may
* still be alive after either returns a `DecodingError`, however.
*/
public func isAlive() -> Bool {
do {
Expand Down
8 changes: 6 additions & 2 deletions Sources/MongoSwiftSync/MongoCursor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,13 @@ public class MongoCursor<T: Codable>: CursorProtocol {
* This method is mainly useful if this cursor is tailable, since in that case `tryNext` may return more results
* even after returning `nil`.
*
* If this cursor is non-tailable, it will always be dead as soon as either `tryNext` returns `nil` or an error.
* If this cursor is non-tailable, it will always be dead after either `tryNext` returns `nil` or a
* non-`DecodingError` error.
*
* This cursor will be dead as soon as `next` returns `nil` or an error, regardless of the `MongoCursorType`.
* This cursor will be dead after `next` returns `nil` or a non-`DecodingError` error, regardless of the
* `MongoCursorType`.
*
* This cursor may still be alive after `next` or `tryNext` returns a `DecodingError`.
*/
public func isAlive() -> Bool {
do {
Expand Down