Skip to content

Commit 3ff9e8d

Browse files
committed
Fix blocking param in http_request on MC servers
Previously only the http request was blocking on MC servers. This makes the callback execution also blocking.
1 parent d6bae47 commit 3ff9e8d

File tree

2 files changed

+21
-18
lines changed

2 files changed

+21
-18
lines changed

src/main/java/com/laytonsmith/core/functions/Web.java

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -483,26 +483,26 @@ public void run() {
483483
if(arrayJar != null) {
484484
getCookieJar(arrayJar, settings.getCookieJar(), t);
485485
}
486-
StaticLayer.GetConvertor().runOnMainThreadLater(
487-
environment.getEnv(StaticRuntimeEnv.class).GetDaemonManager(), new Runnable() {
488-
489-
@Override
490-
public void run() {
491-
executeFinish(success, array, t, environment);
492-
}
493-
});
486+
if(settings.getBlocking()) {
487+
executeFinish(success, array, t, environment);
488+
} else {
489+
StaticLayer.GetConvertor().runOnMainThreadLater(
490+
environment.getEnv(StaticRuntimeEnv.class).GetDaemonManager(),
491+
() -> executeFinish(success, array, t, environment));
492+
}
494493
} catch (IOException e) {
495494
final CREIOException ex = new CREIOException((e instanceof UnknownHostException ? "Unknown host: " : "")
496495
+ e.getMessage(), t);
497496
ex.setStackTraceElements(st);
498497
if(error != null) {
499-
StaticLayer.GetConvertor().runOnMainThreadLater(
500-
environment.getEnv(StaticRuntimeEnv.class).GetDaemonManager(), new Runnable() {
501-
@Override
502-
public void run() {
503-
executeFinish(error, ObjectGenerator.GetGenerator().exception(ex, environment, t), t, environment);
504-
}
505-
});
498+
final CArray cException = ObjectGenerator.GetGenerator().exception(ex, environment, t);
499+
if(settings.getBlocking()) {
500+
executeFinish(error, cException, t, environment);
501+
} else {
502+
StaticLayer.GetConvertor().runOnMainThreadLater(
503+
environment.getEnv(StaticRuntimeEnv.class).GetDaemonManager(),
504+
() -> executeFinish(error, cException, t, environment));
505+
}
506506
} else {
507507
ConfigRuntimeException.HandleUncaughtException(ex, environment);
508508
}

src/main/resources/functionDocs/http_request

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,8 @@ yourself.
9999
| error
100100
| closure
101101
| null
102-
| If the request fails for whatever reason, this receives the exception generated. By default, the exception
103-
is logged using the default uncaught exception handler.
102+
| If the request fails for whatever reason, this receives the [[Exceptions#The exception object|exception object]]
103+
generated. By default, the exception is logged using the default uncaught exception handler.
104104
|-
105105
| timeout
106106
| int
@@ -171,7 +171,10 @@ decides on the encoding format to use.
171171
| blocking
172172
| boolean
173173
| false
174-
| If this is true, the method will block until it is complete, and it also won't use the internal thread pool.
174+
| If this is true, the function will block and execute the success or error callback on the current thread. Otherwise
175+
the request will be executed asynchronously and the success or error callback will be executed on the main thread on a
176+
Minecraft server or a new thread when in cmdline mode. Note that blocking on the main Minecraft thread may disrupt any
177+
online players.
175178
|-
176179
| log
177180
| boolean

0 commit comments

Comments
 (0)