File tree Expand file tree Collapse file tree
driver-core/src/main/com/mongodb/internal/async Expand file tree Collapse file tree Original file line number Diff line number Diff line change 2020import com .mongodb .assertions .Assertions ;
2121import com .mongodb .lang .Nullable ;
2222
23+ import static com .mongodb .assertions .Assertions .assertNotNull ;
24+
2325/**
2426 * A trampoline that converts recursive callback invocations into an iterative loop,
2527 * preventing stack overflow in async loops.
@@ -66,8 +68,10 @@ public static void run(final Runnable work) {
6668 try {
6769 work .run ();
6870 // drain any re-entrant work iteratively
69- while (bounce .hasWork ()) {
70- bounce .runNext ();
71+ while (bounce .work != null ) {
72+ Runnable workToRun = bounce .work ;
73+ bounce .work = null ;
74+ workToRun .run ();
7175 }
7276 } finally {
7377 TRAMPOLINE .remove ();
@@ -91,16 +95,5 @@ void enqueue(final Runnable task) {
9195 }
9296 this .work = task ;
9397 }
94-
95- boolean hasWork () {
96- return work != null ;
97- }
98-
99- void runNext () {
100- Runnable task = this .work ;
101- this .work = null ;
102- Assertions .assertNotNull (task );
103- task .run ();
104- }
10598 }
106- }
99+ }
You can’t perform that action at this time.
0 commit comments