@@ -9,11 +9,13 @@ use std::collections::HashMap;
99use std:: rc:: Rc ;
1010use wasi:: io:: poll:: Pollable ;
1111
12- /// A key representing an entry into the poller
12+ /// A key for a Pollable, which is an index into the Slab<Pollable> in Reactor.
1313#[ repr( transparent) ]
1414#[ derive( Debug , PartialEq , Eq , PartialOrd , Ord , Hash , Clone , Copy ) ]
1515pub ( crate ) struct EventKey ( pub ( crate ) usize ) ;
1616
17+ /// A Registration is a reference to the Reactor's owned Pollable. When the registration is
18+ /// dropped, the reactor will drop the Pollable resource.
1719#[ derive( Debug , PartialEq , Eq , Hash ) ]
1820struct Registration {
1921 key : EventKey ,
@@ -25,10 +27,13 @@ impl Drop for Registration {
2527 }
2628}
2729
30+ /// An AsyncPollable is a reference counted Registration. It can be cloned, and used to create
31+ /// as many WaitFor futures on a Pollable that the user needs.
2832#[ derive( Debug , Clone , PartialEq , Eq , Hash ) ]
2933pub struct AsyncPollable ( Rc < Registration > ) ;
3034
3135impl AsyncPollable {
36+ /// Create a Future that waits for the Pollable's readiness.
3237 pub fn wait_for ( & self ) -> WaitFor {
3338 use std:: sync:: atomic:: { AtomicUsize , Ordering } ;
3439 static COUNTER : AtomicUsize = AtomicUsize :: new ( 0 ) ;
@@ -45,10 +50,13 @@ impl AsyncPollable {
4550
4651#[ derive( Debug , PartialEq , Eq , Hash , Clone ) ]
4752struct Waitee {
53+ /// This needs to be a reference counted registration, because it may outlive the AsyncPollable
54+ /// &self that it was created from.
4855 pollable : AsyncPollable ,
4956 unique : usize ,
5057}
5158
59+ /// A Future that waits for the Pollable's readiness.
5260#[ must_use = "futures do nothing unless polled or .awaited" ]
5361#[ derive( Debug ) ]
5462pub struct WaitFor {
@@ -138,6 +146,8 @@ impl Reactor {
138146 let mut targets = Vec :: with_capacity ( reactor. wakers . len ( ) ) ;
139147 for waitee in reactor. wakers . keys ( ) {
140148 let pollable_index = waitee. pollable . 0 . key ;
149+ // FIXME: instead of storing the indexes, we can actually just stick the waker in here,
150+ // and make the quadratic lookup at the end of this function into a linear lookup.
141151 indexes. push ( pollable_index) ;
142152 targets. push ( & reactor. pollables [ pollable_index. 0 ] ) ;
143153 }
@@ -160,6 +170,7 @@ impl Reactor {
160170 . into_iter ( )
161171 . map ( |index| indexes[ index as usize ] ) ;
162172
173+ // FIXME this doesn't have to be quadratic.
163174 for key in ready_keys {
164175 for ( waitee, waker) in reactor. wakers . iter ( ) {
165176 if waitee. pollable . 0 . key == key {
0 commit comments