Skip to content

Expose Observable[Unit] instead of Observable[Void] #1282

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 5, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class DocumentationTransactionsExampleSpec extends RequiresMongoDBISpec {
})
}

def commitAndRetry(observable: SingleObservable[Void]): SingleObservable[Void] = {
def commitAndRetry(observable: SingleObservable[Unit]): SingleObservable[Unit] = {
observable.recoverWith({
case e: MongoException if e.hasErrorLabel(MongoException.UNKNOWN_TRANSACTION_COMMIT_RESULT_LABEL) => {
println("UnknownTransactionCommitResult, retrying commit operation ...")
Expand All @@ -88,7 +88,7 @@ class DocumentationTransactionsExampleSpec extends RequiresMongoDBISpec {
})
}

def runTransactionAndRetry(observable: SingleObservable[Void]): SingleObservable[Void] = {
def runTransactionAndRetry(observable: SingleObservable[Unit]): SingleObservable[Unit] = {
observable.recoverWith({
case e: MongoException if e.hasErrorLabel(MongoException.TRANSIENT_TRANSACTION_ERROR_LABEL) => {
println("TransientTransactionError, aborting transaction and retrying ...")
Expand All @@ -97,14 +97,14 @@ class DocumentationTransactionsExampleSpec extends RequiresMongoDBISpec {
})
}

def updateEmployeeInfoWithRetry(client: MongoClient): SingleObservable[Void] = {
def updateEmployeeInfoWithRetry(client: MongoClient): SingleObservable[Unit] = {

val database = client.getDatabase("hr")
val updateEmployeeInfoObservable: SingleObservable[ClientSession] =
updateEmployeeInfo(database, client.startSession())
val commitTransactionObservable: SingleObservable[Void] =
val commitTransactionObservable: SingleObservable[Unit] =
updateEmployeeInfoObservable.flatMap(clientSession => clientSession.commitTransaction())
val commitAndRetryObservable: SingleObservable[Void] = commitAndRetry(commitTransactionObservable)
val commitAndRetryObservable: SingleObservable[Unit] = commitAndRetry(commitTransactionObservable)

runTransactionAndRetry(commitAndRetryObservable)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,9 +194,9 @@ case class AggregateObservable[TResult](private val wrapped: AggregatePublisher[
* Aggregates documents according to the specified aggregation pipeline, which must end with a `\$out` stage.
*
* [[https://www.mongodb.com/docs/manual/aggregation/ Aggregation]]
* @return an empty Observable that indicates when the operation has completed
* @return an Observable that indicates when the operation has completed.
*/
def toCollection(): SingleObservable[Void] = wrapped.toCollection()
def toCollection(): SingleObservable[Unit] = wrapped.toCollection()

/**
* Helper to return a single observable limited to the first result.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@ trait ClientSessionImplicits {
*
* A transaction can only be commmited if one has first been started.
*/
def commitTransaction(): SingleObservable[Void] = clientSession.commitTransaction()
def commitTransaction(): SingleObservable[Unit] = clientSession.commitTransaction()

/**
* Abort a transaction in the context of this session.
*
* A transaction can only be aborted if one has first been started.
*/
def abortTransaction(): SingleObservable[Void] = clientSession.abortTransaction()
def abortTransaction(): SingleObservable[Unit] = clientSession.abortTransaction()
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -216,10 +216,10 @@ case class MapReduceObservable[TResult](wrapped: MapReducePublisher[TResult]) ex
* Aggregates documents to a collection according to the specified map-reduce function with the given options, which must specify a
* non-inline result.
*
* @return an empty Observable that indicates when the operation has completed
* @return an Observable that indicates when the operation has completed
* [[https://www.mongodb.com/docs/manual/aggregation/ Aggregation]]
*/
def toCollection(): SingleObservable[Void] = wrapped.toCollection()
def toCollection(): SingleObservable[Unit] = wrapped.toCollection()

/**
* Helper to return a single observable limited to the first result.
Expand Down
88 changes: 44 additions & 44 deletions driver-scala/src/main/scala/org/mongodb/scala/MongoCollection.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1328,44 +1328,44 @@ case class MongoCollection[TResult](private val wrapped: JMongoCollection[TResul
/**
* Drops this collection from the Database.
*
* @return an empty Observable that indicates when the operation has completed
* @return an Observable that indicates when the operation has completed
* [[https://www.mongodb.com/docs/manual/reference/command/drop/ Drop Collection]]
*/
def drop(): SingleObservable[Void] = wrapped.drop()
def drop(): SingleObservable[Unit] = wrapped.drop()

/**
* Drops this collection from the Database.
*
* @param clientSession the client session with which to associate this operation
* @return an empty Observable that indicates when the operation has completed
* @return an Observable that indicates when the operation has completed
* [[https://www.mongodb.com/docs/manual/reference/command/drop/ Drop Collection]]
* @since 2.2
* @note Requires MongoDB 3.6 or greater
*/
def drop(clientSession: ClientSession): SingleObservable[Void] = wrapped.drop(clientSession)
def drop(clientSession: ClientSession): SingleObservable[Unit] = wrapped.drop(clientSession)

/**
* Drops this collection from the Database.
*
* @param dropCollectionOptions various options for dropping the collection
* @return an empty Observable that indicates when the operation has completed
* @return an Observable that indicates when the operation has completed
* [[https://www.mongodb.com/docs/manual/reference/command/drop/ Drop Collection]]
* @since 4.7
* @note Requires MongoDB 6.0 or greater
*/
def drop(dropCollectionOptions: DropCollectionOptions): SingleObservable[Void] = wrapped.drop(dropCollectionOptions)
def drop(dropCollectionOptions: DropCollectionOptions): SingleObservable[Unit] = wrapped.drop(dropCollectionOptions)

/**
* Drops this collection from the Database.
*
* @param clientSession the client session with which to associate this operation
* @param dropCollectionOptions various options for dropping the collection
* @return an empty Observable that indicates when the operation has completed
* @return an Observable that indicates when the operation has completed
* [[https://www.mongodb.com/docs/manual/reference/command/drop/ Drop Collection]]
* @since 4.7
* @note Requires MongoDB 6.0 or greater
*/
def drop(clientSession: ClientSession, dropCollectionOptions: DropCollectionOptions): SingleObservable[Void] =
def drop(clientSession: ClientSession, dropCollectionOptions: DropCollectionOptions): SingleObservable[Unit] =
wrapped.drop(clientSession, dropCollectionOptions)

/**
Expand Down Expand Up @@ -1413,24 +1413,24 @@ case class MongoCollection[TResult](private val wrapped: JMongoCollection[TResul
*
* @param indexName the name of the search index to update.
* @param definition the search index mapping definition.
* @return an empty Observable that indicates when the operation has completed.
* @return an Observable that indicates when the operation has completed.
* @since 4.11
* @note Requires MongoDB 7.0 or greater
* @see [[https://www.mongodb.com/docs/manual/reference/command/updateSearchIndex/ Update Search Index]]
*/
def updateSearchIndex(indexName: String, definition: Bson): SingleObservable[Void] =
def updateSearchIndex(indexName: String, definition: Bson): SingleObservable[Unit] =
wrapped.updateSearchIndex(indexName, definition)

/**
* Drop an Atlas Search index given its name.
*
* @param indexName the name of the search index to drop.
* @return an empty Observable that indicates when the operation has completed.
* @return an Observable that indicates when the operation has completed.
* @since 4.11
* @note Requires MongoDB 7.0 or greater
* @see [[https://www.mongodb.com/docs/manual/reference/command/dropSearchIndex/ Drop Search Index]]
*/
def dropSearchIndex(indexName: String): SingleObservable[Void] = wrapped.dropSearchIndex(indexName)
def dropSearchIndex(indexName: String): SingleObservable[Unit] = wrapped.dropSearchIndex(indexName)

/**
* Get all Atlas Search indexes in this collection.
Expand Down Expand Up @@ -1569,39 +1569,39 @@ case class MongoCollection[TResult](private val wrapped: JMongoCollection[TResul
*
* [[https://www.mongodb.com/docs/manual/reference/command/dropIndexes/ Drop Indexes]]
* @param indexName the name of the index to remove
* @return an empty Observable that indicates when the operation has completed
* @return an Observable that indicates when the operation has completed
*/
def dropIndex(indexName: String): SingleObservable[Void] = wrapped.dropIndex(indexName)
def dropIndex(indexName: String): SingleObservable[Unit] = wrapped.dropIndex(indexName)

/**
* Drops the given index.
*
* [[https://www.mongodb.com/docs/manual/reference/command/dropIndexes/ Drop Indexes]]
* @param indexName the name of the index to remove
* @param dropIndexOptions options to use when dropping indexes
* @return an empty Observable that indicates when the operation has completed
* @return an Observable that indicates when the operation has completed
* @since 2.2
*/
def dropIndex(indexName: String, dropIndexOptions: DropIndexOptions): SingleObservable[Void] =
def dropIndex(indexName: String, dropIndexOptions: DropIndexOptions): SingleObservable[Unit] =
wrapped.dropIndex(indexName, dropIndexOptions)

/**
* Drops the index given the keys used to create it.
*
* @param keys the keys of the index to remove
* @return an empty Observable that indicates when the operation has completed
* @return an Observable that indicates when the operation has completed
*/
def dropIndex(keys: Bson): SingleObservable[Void] = wrapped.dropIndex(keys)
def dropIndex(keys: Bson): SingleObservable[Unit] = wrapped.dropIndex(keys)

/**
* Drops the index given the keys used to create it.
*
* @param keys the keys of the index to remove
* @param dropIndexOptions options to use when dropping indexes
* @return an empty Observable that indicates when the operation has completed
* @return an Observable that indicates when the operation has completed
* @since 2.2
*/
def dropIndex(keys: Bson, dropIndexOptions: DropIndexOptions): SingleObservable[Void] =
def dropIndex(keys: Bson, dropIndexOptions: DropIndexOptions): SingleObservable[Unit] =
wrapped.dropIndex(keys, dropIndexOptions)

/**
Expand All @@ -1610,11 +1610,11 @@ case class MongoCollection[TResult](private val wrapped: JMongoCollection[TResul
* [[https://www.mongodb.com/docs/manual/reference/command/dropIndexes/ Drop Indexes]]
* @param clientSession the client session with which to associate this operation
* @param indexName the name of the index to remove
* @return an empty Observable that indicates when the operation has completed
* @return an Observable that indicates when the operation has completed
* @since 2.2
* @note Requires MongoDB 3.6 or greater
*/
def dropIndex(clientSession: ClientSession, indexName: String): SingleObservable[Void] =
def dropIndex(clientSession: ClientSession, indexName: String): SingleObservable[Unit] =
wrapped.dropIndex(clientSession, indexName)

/**
Expand All @@ -1624,27 +1624,27 @@ case class MongoCollection[TResult](private val wrapped: JMongoCollection[TResul
* @param clientSession the client session with which to associate this operation
* @param indexName the name of the index to remove
* @param dropIndexOptions options to use when dropping indexes
* @return an empty Observable that indicates when the operation has completed
* @return an Observable that indicates when the operation has completed
* @since 2.2
* @note Requires MongoDB 3.6 or greater
*/
def dropIndex(
clientSession: ClientSession,
indexName: String,
dropIndexOptions: DropIndexOptions
): SingleObservable[Void] =
): SingleObservable[Unit] =
wrapped.dropIndex(clientSession, indexName, dropIndexOptions)

/**
* Drops the index given the keys used to create it.
*
* @param clientSession the client session with which to associate this operation
* @param keys the keys of the index to remove
* @return an empty Observable that indicates when the operation has completed
* @return an Observable that indicates when the operation has completed
* @since 2.2
* @note Requires MongoDB 3.6 or greater
*/
def dropIndex(clientSession: ClientSession, keys: Bson): SingleObservable[Void] =
def dropIndex(clientSession: ClientSession, keys: Bson): SingleObservable[Unit] =
wrapped.dropIndex(clientSession, keys)

/**
Expand All @@ -1653,46 +1653,46 @@ case class MongoCollection[TResult](private val wrapped: JMongoCollection[TResul
* @param clientSession the client session with which to associate this operation
* @param keys the keys of the index to remove
* @param dropIndexOptions options to use when dropping indexes
* @return an empty Observable that indicates when the operation has completed
* @return an Observable that indicates when the operation has completed
* @since 2.2
* @note Requires MongoDB 3.6 or greater
*/
def dropIndex(
clientSession: ClientSession,
keys: Bson,
dropIndexOptions: DropIndexOptions
): SingleObservable[Void] =
): SingleObservable[Unit] =
wrapped.dropIndex(clientSession, keys, dropIndexOptions)

/**
* Drop all the indexes on this collection, except for the default on _id.
*
* [[https://www.mongodb.com/docs/manual/reference/command/dropIndexes/ Drop Indexes]]
* @return an empty Observable that indicates when the operation has completed
* @return an Observable that indicates when the operation has completed
*/
def dropIndexes(): SingleObservable[Void] = wrapped.dropIndexes()
def dropIndexes(): SingleObservable[Unit] = wrapped.dropIndexes()

/**
* Drop all the indexes on this collection, except for the default on _id.
*
* [[https://www.mongodb.com/docs/manual/reference/command/dropIndexes/ Drop Indexes]]
* @param dropIndexOptions options to use when dropping indexes
* @return an empty Observable that indicates when the operation has completed
* @return an Observable that indicates when the operation has completed
* @since 2.2
*/
def dropIndexes(dropIndexOptions: DropIndexOptions): SingleObservable[Void] =
def dropIndexes(dropIndexOptions: DropIndexOptions): SingleObservable[Unit] =
wrapped.dropIndexes(dropIndexOptions)

/**
* Drop all the indexes on this collection, except for the default on _id.
*
* [[https://www.mongodb.com/docs/manual/reference/command/dropIndexes/ Drop Indexes]]
* @param clientSession the client session with which to associate this operation
* @return an empty Observable that indicates when the operation has completed
* @return an Observable that indicates when the operation has completed
* @since 2.2
* @note Requires MongoDB 3.6 or greater
*/
def dropIndexes(clientSession: ClientSession): SingleObservable[Void] =
def dropIndexes(clientSession: ClientSession): SingleObservable[Unit] =
wrapped.dropIndexes(clientSession)

/**
Expand All @@ -1701,21 +1701,21 @@ case class MongoCollection[TResult](private val wrapped: JMongoCollection[TResul
* [[https://www.mongodb.com/docs/manual/reference/command/dropIndexes/ Drop Indexes]]
* @param clientSession the client session with which to associate this operation
* @param dropIndexOptions options to use when dropping indexes
* @return an empty Observable that indicates when the operation has completed
* @return an Observable that indicates when the operation has completed
* @since 2.2
* @note Requires MongoDB 3.6 or greater
*/
def dropIndexes(clientSession: ClientSession, dropIndexOptions: DropIndexOptions): SingleObservable[Void] =
def dropIndexes(clientSession: ClientSession, dropIndexOptions: DropIndexOptions): SingleObservable[Unit] =
wrapped.dropIndexes(clientSession, dropIndexOptions)

/**
* Rename the collection with oldCollectionName to the newCollectionName.
*
* [[https://www.mongodb.com/docs/manual/reference/commands/renameCollection Rename collection]]
* @param newCollectionNamespace the name the collection will be renamed to
* @return an empty Observable that indicates when the operation has completed
* @return an Observable that indicates when the operation has completed
*/
def renameCollection(newCollectionNamespace: MongoNamespace): SingleObservable[Void] =
def renameCollection(newCollectionNamespace: MongoNamespace): SingleObservable[Unit] =
wrapped.renameCollection(newCollectionNamespace)

/**
Expand All @@ -1724,12 +1724,12 @@ case class MongoCollection[TResult](private val wrapped: JMongoCollection[TResul
* [[https://www.mongodb.com/docs/manual/reference/commands/renameCollection Rename collection]]
* @param newCollectionNamespace the name the collection will be renamed to
* @param options the options for renaming a collection
* @return an empty Observable that indicates when the operation has completed
* @return an Observable that indicates when the operation has completed
*/
def renameCollection(
newCollectionNamespace: MongoNamespace,
options: RenameCollectionOptions
): SingleObservable[Void] =
): SingleObservable[Unit] =
wrapped.renameCollection(newCollectionNamespace, options)

/**
Expand All @@ -1738,14 +1738,14 @@ case class MongoCollection[TResult](private val wrapped: JMongoCollection[TResul
* [[https://www.mongodb.com/docs/manual/reference/commands/renameCollection Rename collection]]
* @param clientSession the client session with which to associate this operation
* @param newCollectionNamespace the name the collection will be renamed to
* @return an empty Observable that indicates when the operation has completed
* @return an Observable that indicates when the operation has completed
* @since 2.2
* @note Requires MongoDB 3.6 or greater
*/
def renameCollection(
clientSession: ClientSession,
newCollectionNamespace: MongoNamespace
): SingleObservable[Void] =
): SingleObservable[Unit] =
wrapped.renameCollection(clientSession, newCollectionNamespace)

/**
Expand All @@ -1755,15 +1755,15 @@ case class MongoCollection[TResult](private val wrapped: JMongoCollection[TResul
* @param clientSession the client session with which to associate this operation
* @param newCollectionNamespace the name the collection will be renamed to
* @param options the options for renaming a collection
* @return an empty Observable that indicates when the operation has completed
* @return an Observable that indicates when the operation has completed
* @since 2.2
* @note Requires MongoDB 3.6 or greater
*/
def renameCollection(
clientSession: ClientSession,
newCollectionNamespace: MongoNamespace,
options: RenameCollectionOptions
): SingleObservable[Void] =
): SingleObservable[Unit] =
wrapped.renameCollection(clientSession, newCollectionNamespace, options)

/**
Expand Down
Loading