Skip to content

Commit e0a4dd8

Browse files
committed
reformat
1 parent 2b7b7a7 commit e0a4dd8

5 files changed

Lines changed: 12 additions & 38 deletions

File tree

‎.github/workflows/ci.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ jobs:
6363
- uses: dtolnay/rust-toolchain@stable
6464
- id: crates-auth
6565
uses: rust-lang/crates-io-auth-action@v1
66-
- run: cargo publish -p loopmini
66+
- run: cargo publish -p loopmini --no-verify
6767
env:
6868
CARGO_REGISTRY_TOKEN: ${{ steps.crates-auth.outputs.token }}
6969
- uses: actions/download-artifact@v8

‎.gitignore‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
meta/
12
__pycache__/
23
*.py[cod]
34
*.so

‎py/src/pyreactor.rs‎

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,7 @@ impl PyReactor {
3333
py.check_signals()?;
3434
let ControlFlow::Continue(timeout) = self.core.next_timeout() else { return Ok(()) };
3535
let events = match py.detach(|| self.core.poll(timeout)) {
36-
Ok(ev) => ev,
37-
Err(e) if e.kind() == std::io::ErrorKind::Interrupted => Events::new(),
38-
Err(e) => return Err(e.into()),
36+
Ok(ev) => ev, Err(e) if e.kind() == std::io::ErrorKind::Interrupted => Events::new(), Err(e) => return Err(e.into())
3937
};
4038
self.core.process(&events);
4139
let batch = self.core.take_batch();
@@ -44,14 +42,7 @@ impl PyReactor {
4442
// An injected async exception (e.g. KeyboardInterrupt) can surface at either
4543
// Python call; only a handle whose _run began may be dropped without requeue.
4644
let cancelled = h.bind(py).getattr(intern!(py, "_cancelled")).and_then(|v| v.extract::<bool>());
47-
match cancelled {
48-
Err(e) => {
49-
self.core.requeue_front(std::iter::once(h).chain(it));
50-
return Err(e);
51-
}
52-
Ok(true) => continue,
53-
Ok(false) => {}
54-
}
45+
match cancelled { Err(e) => { self.core.requeue_front(std::iter::once(h).chain(it)); return Err(e); } Ok(true) => continue, Ok(false) => {} }
5546
if let Err(e) = h.bind(py).call_method0(intern!(py, "_run")) {
5647
// An injected exception surfacing at `_run`'s entry leaves a single-frame
5748
// traceback: the callback never ran, so requeue the handle - dropping it

‎rustfmt.toml‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1 @@
1-
max_width = 160
2-
use_small_heuristics = "Max"
3-
use_field_init_shorthand = true
41
disable_all_formatting = true

‎src/reactor.rs‎

Lines changed: 8 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,7 @@ impl<H> Default for FdEntry<H> { fn default() -> Self { Self { reader: None, wri
1313

1414
fn interest<H>(key: usize, e: &FdEntry<H>) -> Event {
1515
match (e.reader.is_some(), e.writer.is_some()) {
16-
(true, true) => Event::all(key),
17-
(true, false) => Event::readable(key),
18-
(false, true) => Event::writable(key),
19-
(false, false) => Event::none(key),
16+
(true, true) => Event::all(key), (true, false) => Event::readable(key), (false, true) => Event::writable(key), (false, false) => Event::none(key)
2017
}
2118
}
2219

@@ -30,21 +27,12 @@ struct Inner<H> {
3027
stop: bool,
3128
}
3229

33-
pub struct Reactor<H> {
34-
inner: Mutex<Inner<H>>,
35-
tsq: Mutex<VecDeque<H>>,
36-
poller: Poller,
37-
start: Instant,
38-
}
30+
pub struct Reactor<H> { inner: Mutex<Inner<H>>, tsq: Mutex<VecDeque<H>>, poller: Poller, start: Instant }
3931

4032
impl<H: Clone> Reactor<H> {
4133
pub fn new() -> io::Result<Self> {
42-
Ok(Self {
43-
inner: Mutex::new(Inner { ready: VecDeque::new(), timers: BTreeMap::new(), fds: HashMap::new(), seq: 0, stop: false }),
44-
tsq: Mutex::new(VecDeque::new()),
45-
poller: Poller::new()?,
46-
start: Instant::now(),
47-
})
34+
Ok(Self { inner: Mutex::new(Inner { ready: VecDeque::new(), timers: BTreeMap::new(), fds: HashMap::new(), seq: 0, stop: false }),
35+
tsq: Mutex::new(VecDeque::new()), poller: Poller::new()?, start: Instant::now() })
4836
}
4937

5038
fn now_us(&self) -> u64 { self.start.elapsed().as_micros() as u64 }
@@ -91,8 +79,7 @@ impl<H: Clone> Reactor<H> {
9179
if empty {
9280
inner.fds.remove(&fd);
9381
let _ = self.poller.delete(borrowed(fd));
94-
}
95-
else { self.poller.modify(borrowed(fd), ev)? }
82+
} else { self.poller.modify(borrowed(fd), ev)? }
9683
Ok(had)
9784
}
9885

@@ -118,10 +105,7 @@ impl<H: Clone> Reactor<H> {
118105
/// cross-thread handles, and say how long the driver may block in `poll`.
119106
pub fn next_timeout(&self) -> ControlFlow<(), Option<Duration>> {
120107
let mut inner = self.inner.lock().unwrap();
121-
if inner.stop {
122-
inner.stop = false;
123-
return ControlFlow::Break(());
124-
}
108+
if inner.stop { inner.stop = false; return ControlFlow::Break(()); }
125109
let Inner { ready, timers, .. } = &mut *inner;
126110
self.drain_tsq(ready);
127111
let now = self.now_us();
@@ -133,7 +117,8 @@ impl<H: Clone> Reactor<H> {
133117
// to u64::MAX, and a pure-Rust consumer blocking in `poll` would hand that
134118
// timespec to kqueue, which rejects it with EINVAL
135119
const MAX_POLL_US: u64 = 86_400_000_000;
136-
ControlFlow::Continue(if !ready.is_empty() { Some(Duration::ZERO) } else { timers.first_key_value().map(|((when, _), _)| Duration::from_micros((when - now + 1).min(MAX_POLL_US))) })
120+
ControlFlow::Continue(if !ready.is_empty() { Some(Duration::ZERO) }
121+
else { timers.first_key_value().map(|((when, _), _)| Duration::from_micros((when - now + 1).min(MAX_POLL_US))) })
137122
}
138123

139124
/// Blocking wait; holds no locks, so drivers may run it with the GIL released.

0 commit comments

Comments
 (0)