Skip to content

Commit dc9a01b

Browse files
committed
remove IShutDown, pass shutdown function to createLuvGen instead
1 parent 6d2f9c0 commit dc9a01b

File tree

3 files changed

+18
-11
lines changed

3 files changed

+18
-11
lines changed

src/hxcoro/dispatchers/LuvDispatcher.cpp.hx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import haxe.coro.schedulers.IScheduler;
88
import haxe.ds.Option;
99
import hxcoro.schedulers.LuvScheduler;
1010

11-
class LuvDispatcher extends Dispatcher implements IShutDown
11+
class LuvDispatcher extends Dispatcher
1212
{
1313
final loop:LuvLoop;
1414
final workQueue:AsyncDeque<()->Void>;

src/hxcoro/run/Setup.hx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
package hxcoro.run;
22

3-
import haxe.coro.schedulers.IScheduler;
4-
import hxcoro.dispatchers.IShutDown;
53
import haxe.coro.BaseContinuation;
64
import haxe.coro.context.Context;
75
import haxe.coro.dispatchers.Dispatcher;
6+
import haxe.coro.schedulers.IScheduler;
87
import hxcoro.schedulers.ILoop;
98

109
class Setup {
@@ -59,23 +58,24 @@ class Setup {
5958

6059
#if (cpp && hxcpp_luv_io)
6160

62-
static public function createLuvGen(createDispatcher:(cpp.luv.Luv.LuvLoop, IScheduler) -> Dispatcher) {
61+
static public function createLuvGen<T:Dispatcher>(createDispatcher:(cpp.luv.Luv.LuvLoop, IScheduler) -> T, shutDownDispatcher:T -> Void) {
6362
final loop = cpp.luv.Luv.allocLoop();
6463
final scheduler = new hxcoro.schedulers.LuvScheduler(loop);
6564
final dispatcher = createDispatcher(loop, scheduler);
6665
function finalize() {
6766
scheduler.shutDown();
68-
if (dispatcher is IShutDown) {
69-
(cast dispatcher : IShutDown).shutDown();
70-
}
67+
shutDownDispatcher(dispatcher);
7168
cpp.luv.Luv.stopLoop(loop);
7269
cpp.luv.Luv.freeLoop(loop);
7370
}
7471
return new LoopSetup(scheduler, dispatcher, finalize);
7572
}
7673

7774
static public function createLuv() {
78-
return createLuvGen((uvLoop, loop) -> new hxcoro.dispatchers.LuvDispatcher(uvLoop, loop));
75+
return createLuvGen(
76+
(uvLoop, loop) -> new hxcoro.dispatchers.LuvDispatcher(uvLoop, loop),
77+
dispatcher -> dispatcher.shutDown()
78+
);
7979
}
8080

8181
#elseif interp

tests/src/run/TestEntrypoints.hx

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,10 @@ class TestEntrypoints extends utest.Test {
142142
#if (cpp && hxcpp_luv_io)
143143

144144
public function testLuvTrampoline() {
145-
final setup = Setup.createLuvGen((uvLoop, loop) -> new TrampolineDispatcher(loop));
145+
final setup = Setup.createLuvGen(
146+
(uvLoop, loop) -> new TrampolineDispatcher(loop),
147+
_ -> {}
148+
);
146149
final context = setup.createContext();
147150
runSuite(context, setup.loop);
148151
setup.close();
@@ -151,11 +154,15 @@ class TestEntrypoints extends utest.Test {
151154

152155
public function testLuvThreadPool() {
153156
final pool = new hxcoro.thread.FixedThreadPool(1);
154-
final setup = Setup.createLuvGen((uvLoop, loop) -> new ThreadPoolDispatcher(loop, pool));
157+
final setup = Setup.createLuvGen(
158+
(uvLoop, loop) -> new ThreadPoolDispatcher(loop, pool),
159+
dispatcher -> {
160+
pool.shutDown();
161+
}
162+
);
155163
final context = setup.createContext();
156164
runSuite(context, setup.loop);
157165
setup.close();
158-
pool.shutDown();
159166
}
160167

161168
// public function testLuvLuv() {

0 commit comments

Comments
 (0)