Skip to content

Commit

Permalink
Including .crate-docs.md
Browse files Browse the repository at this point in the history
Also fixing clippy and updating dependencies.
  • Loading branch information
ecton committed Dec 29, 2023
1 parent 56c664d commit a852135
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 13 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,20 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## Unreleased
## v1.1.2

### Changed

- `Watcher<T>` now uses interior mutability via `AtomicUsize`. This allows a
watcher to be stored inside of a static variable and be used between multiple
threads without involving a mutex.
- This package's MSRV was incorrectly set. It has been updated to 1.64, which
was the actual MSRV of 1.1.1

### Fixes

- `Watcher<T>` no longer requires `T` to be `Clone` for itself to be cloneable.
- `.crate-docs.md` is now included in the released package.

## v1.1.1

Expand Down
7 changes: 4 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
[package]
name = "watchable"
version = "1.1.1"
version = "1.1.2"
edition = "2021"
description = "A watchable RwLock-like type that is compatible with both multi-threaded and async code."
repository = "https://github.com/khonsulabs/watchable"
license = "MIT OR Apache-2.0"
keywords = ["asynchronous", "async", "thread", "mpmc"]
categories = ["concurrency", "data-structures", "asynchronous"]
readme = "./README.md"
rust-version = "1.58"
rust-version = "1.64"
include = ["/src", "/src/*.md", "examples", "LICENSE-APACHE", "LICENSE-MIT"]

[dependencies]
event-listener = "2.5.2"
event-listener = "4.0.1"
parking_lot = "0.12.0"
futures-util = "0.3.21"
thiserror = "1.0.30"
Expand Down
19 changes: 10 additions & 9 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

use std::{
ops::{Deref, DerefMut},
pin::Pin,
sync::{
atomic::{AtomicUsize, Ordering},
Arc,
Expand Down Expand Up @@ -307,7 +308,7 @@ pub enum TimeoutError {
}

impl<T> Watcher<T> {
fn create_listener_if_needed(&self) -> Result<EventListener, CreateListenerError> {
fn create_listener_if_needed(&self) -> Result<Pin<Box<EventListener>>, CreateListenerError> {
let changed = self.watched.changed.read();
match (changed.as_ref(), self.is_current()) {
(_, false) => Err(CreateListenerError::NewValueAvailable),
Expand Down Expand Up @@ -368,8 +369,8 @@ impl<T> Watcher<T> {
pub fn watch(&self) -> Result<(), Disconnected> {
loop {
match self.create_listener_if_needed() {
Ok(listener) => {
listener.wait();
Ok(mut listener) => {
listener.as_mut().wait();
if !self.is_current() {
break;
}
Expand Down Expand Up @@ -412,8 +413,8 @@ impl<T> Watcher<T> {
pub fn watch_until(&self, deadline: Instant) -> Result<(), TimeoutError> {
loop {
match self.create_listener_if_needed() {
Ok(listener) => {
if listener.wait_deadline(deadline) {
Ok(mut listener) => {
if listener.as_mut().wait_deadline(deadline).is_some() {
if !self.is_current() {
break;
} else if Instant::now() < deadline {
Expand Down Expand Up @@ -499,7 +500,7 @@ impl<T> Watcher<T> {
where
T: Clone,
{
self.watch().map(|_| self.read().clone())
self.watch().map(|()| self.read().clone())
}

/// Watches for a new value to be stored in the source [`Watchable`] and
Expand All @@ -518,7 +519,7 @@ impl<T> Watcher<T> {
where
T: Clone,
{
self.watch_async().await.map(|_| self.read().clone())
self.watch_async().await.map(|()| self.read().clone())
}

/// Returns this watcher in a type that implements [`Stream`].
Expand Down Expand Up @@ -546,7 +547,7 @@ where
#[must_use]
pub struct WatcherStream<T> {
watcher: Watcher<T>,
listener: Option<EventListener>,
listener: Option<Pin<Box<EventListener>>>,
}

impl<T> WatcherStream<T> {
Expand Down Expand Up @@ -577,7 +578,7 @@ where
{
Ok(mut listener) => {
match listener.poll_unpin(cx) {
Poll::Ready(_) => {
Poll::Ready(()) => {
if !self.watcher.is_current() {
break;
}
Expand Down

0 comments on commit a852135

Please sign in to comment.