Skip to content

Commit

Permalink
Merge pull request #36 from palantir/bind-drop-on-complete
Browse files Browse the repository at this point in the history
Drop the span on future completion, not drop
  • Loading branch information
sfackler authored Jan 21, 2021
2 parents a04f8a2 + 06d922b commit 298ac74
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
2 changes: 1 addition & 1 deletion zipkin/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "zipkin"
version = "0.4.1"
version = "0.4.2"
authors = ["Steven Fackler <sfackler@palantir.com>"]
edition = "2018"
license = "Apache-2.0"
Expand Down
24 changes: 19 additions & 5 deletions zipkin/src/open_span.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,17 +185,20 @@ impl OpenSpan<Detached> {
where
F: Future,
{
Bind { span: self, future }
Bind {
span: Some(self),
future,
}
}
}

pin_project! {
/// A type which wraps a future, associating it with an `OpenSpan`.
///
/// The span's context will be set as the current whenever it's polled, and the span will close
/// when the future is dropped.
/// when the future completes.
pub struct Bind<T> {
span: OpenSpan<Detached>,
span: Option<OpenSpan<Detached>>,
#[pin]
future: T,
}
Expand All @@ -209,7 +212,18 @@ where

fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
let this = self.project();
let _guard = crate::set_current(this.span.context());
this.future.poll(cx)
let _guard = crate::set_current(
this.span
.as_ref()
.expect("future polled after completion")
.context(),
);

let r = this.future.poll(cx);
if r.is_ready() {
*this.span = None;
}

r
}
}

0 comments on commit 298ac74

Please sign in to comment.