Skip to content

Commit

Permalink
Use idiomatic method for writing Option and accessing inner T
Browse files Browse the repository at this point in the history
  • Loading branch information
paolobarbolini authored and caspervonb committed Jul 17, 2023
1 parent fa6a885 commit 326a845
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
4 changes: 2 additions & 2 deletions async-nats/src/jetstream/consumer/pull.rs
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ impl<'a> futures::Stream for Sequence<'a> {
let request = self.request.clone();
let pending_messages = self.pending_messages;

self.next = Some(Box::pin(async move {
let next = self.next.insert(Box::pin(async move {
let inbox = context.client.new_inbox();
let subscriber = context
.client
Expand All @@ -484,7 +484,7 @@ impl<'a> futures::Stream for Sequence<'a> {
})
}));

match self.next.as_mut().unwrap().as_mut().poll(cx) {
match next.as_mut().poll(cx) {
Poll::Ready(result) => {
self.next = None;
Poll::Ready(Some(result.map_err(|err| {
Expand Down
21 changes: 11 additions & 10 deletions async-nats/src/jetstream/consumer/push.rs
Original file line number Diff line number Diff line change
Expand Up @@ -578,16 +578,17 @@ impl<'a> futures::Stream for Ordered<'a> {
let sequence = self.stream_sequence.clone();
let config = self.consumer.config.clone();
let stream_name = self.consumer.info.stream_name.clone();
self.subscriber_future = Some(Box::pin(async move {
recreate_consumer_and_subscription(
context,
config,
stream_name,
sequence.load(Ordering::Relaxed),
)
.await
}));
match self.subscriber_future.as_mut().unwrap().as_mut().poll(cx) {
let subscriber_future =
self.subscriber_future.insert(Box::pin(async move {
recreate_consumer_and_subscription(
context,
config,
stream_name,
sequence.load(Ordering::Relaxed),
)
.await
}));
match subscriber_future.as_mut().poll(cx) {
Poll::Ready(subscriber) => {
self.subscriber_future = None;
self.subscriber = Some(subscriber.map_err(|err| {
Expand Down

0 comments on commit 326a845

Please sign in to comment.