Skip to content

Commit

Permalink
Address some mistakes and nits.
Browse files Browse the repository at this point in the history
  • Loading branch information
richard-uk1 committed Dec 5, 2019
1 parent 5e45199 commit ea552dc
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 11 deletions.
4 changes: 2 additions & 2 deletions crates/events/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ provides an [`EventListener`] type which makes it easy!
See the documentation for [`EventListener`] for more information.
[`EventListener`]: https://docs.rs/gloo-events/^0.1.0/gloo_events/struct.EventListener.html
[`EventListener`]: struct.EventListener.html
*/
#![deny(missing_docs, missing_debug_implementations)]

Expand Down Expand Up @@ -224,7 +224,7 @@ thread_local! {
/// impl Stream for OnClick {
/// type Item = ();
///
/// fn poll_next(self: Pin<&mut Self>, cx: &mut Context) -> Poll<Option<Self::Item>> {
/// fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context) -> Poll<Option<Self::Item>> {
/// Pin::new(&mut self.receiver).poll_next(cx)
/// }
/// }
Expand Down
10 changes: 3 additions & 7 deletions crates/timers/src/future.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ impl TimeoutFuture {
let (tx, rx) = oneshot::channel();
let inner = Timeout::new(millis, move || {
// if the receiver was dropped we do nothing.
let _ = tx.send(());
tx.send(()).unwrap_throw();
});
TimeoutFuture { inner, rx }
}
Expand All @@ -76,11 +76,7 @@ impl Future for TimeoutFuture {
type Output = ();

fn poll(mut self: Pin<&mut Self>, cx: &mut Context) -> Poll<Self::Output> {
match Future::poll(Pin::new(&mut self.rx), cx) {
Poll::Pending => Poll::Pending,
Poll::Ready(Ok(t)) => Poll::Ready(t),
Poll::Ready(Err(e)) => panic!("{}", e),
}
Future::poll(Pin::new(&mut self.rx), cx).map(|t| t.unwrap_throw())
}
}
/// A scheduled interval as a `Stream`.
Expand Down Expand Up @@ -122,7 +118,7 @@ impl IntervalStream {
let (sender, receiver) = mpsc::unbounded();
let inner = Interval::new(millis, move || {
// if the receiver was dropped we do nothing.
let _ = sender.unbounded_send(());
sender.unbounded_send(()).unwrap_throw();
});

IntervalStream { receiver, inner }
Expand Down
2 changes: 1 addition & 1 deletion crates/timers/tests/web.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ async fn timeout_future_cancel() {
let cell = cell.clone();
move |_| {
cell.set(true);
2 as u32
2u32
}
});

Expand Down
2 changes: 1 addition & 1 deletion examples/clock/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "clock"
version = "0.1.0"
authors = ["Richard Dodd <richard.o.dodd@gmail.com>"]
authors = ["Rust and WebAssembly Working Group"]
edition = "2018"

[lib]
Expand Down
6 changes: 6 additions & 0 deletions examples/clock/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ pub fn main() {
console_error_panic_hook::set_once();
let document = web_sys::window().unwrap_throw().document().unwrap_throw();
let el = document.get_element_by_id("clock").unwrap_throw();

// render the date, then set it to re-render every second.
render_date(&el);
spawn_local(async move {
IntervalStream::new(1_000).for_each(|_| {
Expand All @@ -18,13 +20,17 @@ pub fn main() {
});
}

/// Render the date with the `:` flashing every second into `el`.
fn render_date(el: &web_sys::Element) {
// print the current date
let date = chrono::Local::now();
let format_str = if date.second() % 2 == 0 {
"%Y-%m-%d %H %M"
} else {
"%Y-%m-%d %H:%M"
};
let date_str = date.format(format_str).to_string();

// Set the contents of `el` to our date string
el.set_text_content(Some(&date_str));
}

0 comments on commit ea552dc

Please sign in to comment.