Skip to content
Open
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
17 changes: 10 additions & 7 deletions async-nats/src/jetstream/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ use futures::{Future, StreamExt, TryFutureExt};
use serde::de::DeserializeOwned;
use serde::{Deserialize, Serialize};
use serde_json::{self, json};
use std::borrow::Borrow;
use std::fmt::Display;
use std::future::IntoFuture;
use std::pin::Pin;
Expand Down Expand Up @@ -510,7 +509,7 @@ impl Context {
/// let jetstream = async_nats::jetstream::new(client);
///
/// let stream = jetstream
/// .update_stream(&Config {
/// .update_stream(Config {
/// name: "events".to_string(),
/// discard: DiscardPolicy::New,
/// max_messages: 50_000,
Expand All @@ -520,11 +519,11 @@ impl Context {
/// # Ok(())
/// # }
/// ```
pub async fn update_stream<S>(&self, config: S) -> Result<Info, UpdateStreamError>
pub async fn update_stream<S>(&self, config: S) -> Result<Stream, UpdateStreamError>
where
S: Borrow<Config>,
S: Into<Config>,
{
let config = config.borrow();
let config: Config = config.into();

if config.name.is_empty() {
return Err(CreateStreamError::new(
Expand All @@ -539,9 +538,13 @@ impl Context {
}

let subject = format!("STREAM.UPDATE.{}", config.name);
match self.request(subject, config).await? {
match self.request(subject, &config).await? {
Response::Err { error } => Err(error.into()),
Response::Ok(info) => Ok(info),
Response::Ok(info) => Ok(Stream {
context: self.clone(),
info,
name: config.name,
}),
}
}

Expand Down
3 changes: 2 additions & 1 deletion async-nats/tests/jetstream_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,7 @@ mod jetstream {
let context = async_nats::jetstream::new(client);

let _stream = context.create_stream("events").await.unwrap();
let info = context
let stream = context
.update_stream(stream::Config {
name: "events".into(),
max_messages: 1000,
Expand All @@ -559,6 +559,7 @@ mod jetstream {
})
.await
.unwrap();
let info = &stream.cached_info();
context.update_stream(&info.config).await.unwrap();
assert_eq!(info.config.max_messages, 1000);
assert_eq!(info.config.max_messages_per_subject, 100);
Expand Down