Skip to content

Conversation

@roma-glushko
Copy link
Owner

@roma-glushko roma-glushko commented Sep 1, 2025

Changes

  • Introduced the tokio runtime to power watch/unwatch/event methods
  • removed sync API for now
  • removed anyio

@roma-glushko roma-glushko self-assigned this Sep 1, 2025
@roma-glushko roma-glushko marked this pull request as draft September 1, 2025 09:11
@roma-glushko roma-glushko requested a review from Copilot September 1, 2025 09:11
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR introduces true asynchronous support to the notifykit API by replacing the existing blocking/polling mechanism with Tokio-based async operations. The changes enable proper async file watching without blocking threads.

  • Replaced synchronous get() polling method with async event streaming using Tokio broadcast channels
  • Converted watch() and unwatch() methods to async operations using pyo3_asyncio
  • Introduced background task-based event processing with proper async iteration support

Reviewed Changes

Copilot reviewed 10 out of 12 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
src/watcher.rs Core async refactor: added Tokio broadcast channels, background event processing task, and proper async event handling
src/lib.rs Updated Python bindings to use async methods and added EventBatchIter for proper async iteration
src/events/mod.rs Added Clone trait to EventType enum for broadcast channel compatibility
notifykit/_notifier.py Simplified Python interface to use native async patterns instead of polling
examples/awatch_dir_recursively.py Updated example to use new async watch() method
Cargo.toml Added required async dependencies (pyo3-asyncio, tokio)
Comments suppressed due to low confidence (1)

src/lib.rs:1

  • Silently dropping events on channel overflow could lead to missed file system events. Consider logging when events are dropped or implementing backpressure handling.
mod events;

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment on lines 151 to 177
thread::spawn(move || {
let rt = tokio::runtime::Runtime::new().expect("tokio rt");
rt.block_on(async move {
let mut ticker = time::interval(debounce_delay);

loop {
tokio::select! {
_ = &mut stop_rx => break,
_ = ticker.tick() => {
let (raw, errs) = {
let mut p = proc.lock().unwrap();
(p.get_events(), p.get_errors())
};
if debug && !raw.is_empty() { println!("processed: {:?}", raw); }
if !errs.is_empty() { eprintln!("errors: {:?}", errs); }
if raw.is_empty() { continue; }

let mut batch = Vec::with_capacity(raw.len());
for r in raw {
if let Some(ev) = create_event(&r) { batch.push(ev); }
}

if !batch.is_empty() { let _ = tx.send(batch); } // drop on overflow
}
}
}
});
Copy link

Copilot AI Sep 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Creating a new Tokio runtime inside a spawned thread is inefficient and can cause issues. Consider using Handle::current() to use the existing runtime or restructure to avoid nested runtimes.

Copilot uses AI. Check for mistakes.
Comment on lines +58 to +59
.await
.ok();
Copy link

Copilot AI Sep 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Silently ignoring the Result with .ok() hides potential errors from spawn_blocking. Consider proper error handling or at least logging the error.

Copilot uses AI. Check for mistakes.
Comment on lines +74 to +75
.await
.ok();
Copy link

Copilot AI Sep 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Silently ignoring the Result with .ok() hides potential errors from spawn_blocking. Consider proper error handling or at least logging the error.

Copilot uses AI. Check for mistakes.
@roma-glushko roma-glushko added the Full Build Build notifykit for all supported platforms label Sep 2, 2025
@roma-glushko roma-glushko marked this pull request as ready for review September 2, 2025 19:55
@roma-glushko roma-glushko added the enhancement New feature or request label Sep 2, 2025
@roma-glushko roma-glushko merged commit 7245359 into main Sep 2, 2025
17 checks passed
@roma-glushko roma-glushko deleted the async-notifykit-rs branch September 2, 2025 20:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request Full Build Build notifykit for all supported platforms

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant