@@ -42,11 +42,15 @@ const MAX_INSERT_DOCS_BYTES: usize = 16 * 1000 * 1000;
42
42
/// [`Database::collection_with_options`](struct.Database.html#method.collection_with_options).
43
43
///
44
44
/// `Collection` uses [`std::sync::Arc`](https://doc.rust-lang.org/std/sync/struct.Arc.html) internally,
45
- /// so it can safely be shared across threads. For example:
45
+ /// so it can safely be shared across threads or async tasks . For example:
46
46
///
47
47
/// ```rust
48
48
/// # use bson::{bson, doc};
49
49
/// # use mongodb::error::Result;
50
+ /// # #[cfg(feature = "async-std-runtime")]
51
+ /// # use async_std::task;
52
+ /// # #[cfg(feature = "tokio-runtime")]
53
+ /// # use tokio::task;
50
54
/// #
51
55
/// # #[cfg(not(feature = "sync"))]
52
56
/// # async fn start_workers() -> Result<()> {
@@ -58,15 +62,12 @@ const MAX_INSERT_DOCS_BYTES: usize = 16 * 1000 * 1000;
58
62
/// for i in 0..5 {
59
63
/// let coll_ref = coll.clone();
60
64
///
61
- /// std::thread:: spawn(move || {
65
+ /// task:: spawn(async move {
62
66
/// // Perform operations with `coll_ref`. For example:
63
- /// coll_ref.insert_one(doc! { "x": i }, None);
67
+ /// coll_ref.insert_one(doc! { "x": i }, None).await ;
64
68
/// });
65
69
/// }
66
70
/// #
67
- /// # // Technically we should join the threads here, but for the purpose of the example, we'll just
68
- /// # // sleep for a bit.
69
- /// # std::thread::sleep(std::time::Duration::from_secs(3));
70
71
/// # Ok(())
71
72
/// # }
72
73
/// ```
0 commit comments