Created
May 22, 2020 09:21
-
-
Save AndrejMitrovic/6b03b22859e36ff7000aa5b0d65956ae to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/source/geod24/LocalRest.d b/source/geod24/LocalRest.d | |
index 9c56196..71b85aa 100644 | |
--- a/source/geod24/LocalRest.d | |
+++ b/source/geod24/LocalRest.d | |
@@ -246,10 +246,6 @@ private final class LocalScheduler : C.FiberScheduler | |
/// We need a scheduler to simulate an event loop and to be re-entrant | |
private LocalScheduler scheduler; | |
-/// Whether this is the main thread | |
-private bool is_main_thread; | |
- | |
- | |
/******************************************************************************* | |
Provide eventloop-like functionalities | |
@@ -757,13 +753,6 @@ public final class RemoteAPI (API, alias S = VibeJSONSerializer!()) : API | |
mixin(q{ | |
override ReturnType!(ovrld) } ~ member ~ q{ (Parameters!ovrld params) | |
{ | |
- // we are in the main thread | |
- if (scheduler is null) | |
- { | |
- scheduler = new LocalScheduler; | |
- is_main_thread = true; | |
- } | |
- | |
// `geod24.concurrency.send/receive[Only]` is not `@safe` but | |
// this overload needs to be | |
auto res = () @trusted { | |
@@ -780,25 +769,26 @@ public final class RemoteAPI (API, alias S = VibeJSONSerializer!()) : API | |
// for the main thread, we run the "event loop" until | |
// the request we're interested in receives a response. | |
- if (is_main_thread) | |
+ if (scheduler is null) | |
{ | |
+ scope main_scheduler = new LocalScheduler; | |
bool terminated = false; | |
runTask(() { | |
while (!terminated) | |
{ | |
C.receiveTimeout(C.thisTid(), 10.msecs, | |
(Response res) { | |
- scheduler.pending = res; | |
- scheduler.waiting[res.id].c.notify(); | |
+ main_scheduler.pending = res; | |
+ main_scheduler.waiting[res.id].c.notify(); | |
}); | |
- scheduler.yield(); | |
+ main_scheduler.yield(); | |
} | |
}); | |
Response res; | |
- scheduler.start(() { | |
- res = scheduler.waitResponse(command.id, this.timeout); | |
+ main_scheduler.start(() { | |
+ res = main_scheduler.waitResponse(command.id, this.timeout); | |
terminated = true; | |
}); | |
return res; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment