Claude runtime review
This commit is contained in:
@@ -26,8 +26,11 @@ impl<T: Send + 'static> CompletionState<T> {
|
||||
return;
|
||||
}
|
||||
|
||||
// Queue as a macrotask: I/O completion events belong to the macrotask
|
||||
// queue, consistent with the JavaScript event-loop model where I/O
|
||||
// callbacks are macrotasks and the microtask queue is thread-local only.
|
||||
let state = Arc::clone(self);
|
||||
if !self.owner.queue_microtask(move || {
|
||||
if !self.owner.queue_task(move || {
|
||||
state.wake_queued.store(false, Ordering::Release);
|
||||
if let Some(waker) = state.waker.lock().unwrap().take() {
|
||||
waker.wake();
|
||||
@@ -138,10 +141,25 @@ impl<T> Drop for CompletionFuture<T> {
|
||||
let _ = self.state.result.lock().unwrap().take();
|
||||
let _ = self.state.waker.lock().unwrap().take();
|
||||
|
||||
if !self.state.finished.load(Ordering::Acquire)
|
||||
&& let Some(cancel) = self.state.cancel.lock().unwrap().take()
|
||||
{
|
||||
if self.state.finished.load(Ordering::Acquire) {
|
||||
return;
|
||||
}
|
||||
|
||||
if let Some(cancel) = self.state.cancel.lock().unwrap().take() {
|
||||
// Delegate to the cancel callback (e.g. submit an io_uring cancel).
|
||||
// The actual I/O completion will eventually call handle.finish(),
|
||||
// which decrements pending_ops.
|
||||
cancel();
|
||||
} else {
|
||||
// No cancel callback was registered — this happens when submit_operation
|
||||
// failed before set_cancel could be called, leaving no path through
|
||||
// which finish() would run. Decrement pending_ops directly so the
|
||||
// runtime does not stall indefinitely waiting for an operation that
|
||||
// will never complete. The swap is atomic: if finish() races to set
|
||||
// finished first, the swap returns true and we skip the decrement.
|
||||
if !self.state.finished.swap(true, Ordering::AcqRel) {
|
||||
self.state.owner.finish_async_operation();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user