Skip to content

Commit e0e2044

Browse files
committed
Review changes
1 parent 3cc0221 commit e0e2044

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/webcore/executor.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
// onto the JavaScript event loop. This implementation assumes there is a
33
// single thread and is *not* compatible with multiple WebAssembly workers sharing
44
// the same address space.
5+
//
6+
// TODO: Implement support for multiple threads. This will require a mechanism to
7+
// wake up another thread, such as the `postMessage` API.
58

69
use futures::future::{Future, ExecuteError, Executor};
710
use futures::executor::{self, Notify, Spawn};
@@ -14,6 +17,7 @@ use webcore::try_from::TryInto;
1417
use webcore::value::Reference;
1518

1619

20+
// TODO: Determine optimal values for these constants
1721
// Initial capacity of the event queue
1822
const INITIAL_QUEUE_CAPACITY: usize = 10;
1923
// Iterations to wait before allowing the queue to shrink
@@ -170,6 +174,7 @@ impl EventLoopInner {
170174
fn pop_task(&self) -> Option< Rc< SpawnedTask > > {
171175
self.microtask_queue.borrow_mut().pop_front()
172176
}
177+
// Reclaim space from the queue if it's going to waste
173178
fn shrink_if_necessary(&self) {
174179
let mut queue = self.microtask_queue.borrow_mut();
175180
// We consider shrinking the queue if it is less than
@@ -179,7 +184,7 @@ impl EventLoopInner {
179184
// `QUEUE_SHRINK_DELAY` iterations.
180185
let shrink_counter = self.shrink_counter.get();
181186
if shrink_counter < QUEUE_SHRINK_DELAY {
182-
self.shrink_counter.set(shrink_counter+1);
187+
self.shrink_counter.set(shrink_counter + 1);
183188
} else {
184189
queue.shrink_to_fit();
185190
self.shrink_counter.set(0);
@@ -190,10 +195,10 @@ impl EventLoopInner {
190195
}
191196
// Poll the queue until it is empty
192197
fn drain(&self) {
198+
self.shrink_if_necessary();
193199
while let Some(task) = self.pop_task() {
194200
task.poll();
195201
}
196-
self.shrink_if_necessary();
197202
}
198203
}
199204

0 commit comments

Comments
 (0)