feat: CommandExecSession 的 waitFor(long) 方法支持通过返回值传递是否超时.

现在 waitFor(long) 方法在超过指定时间返回后, 将会通过 boolean 返回值告诉调用方是否超时.
详细信息见 Javadoc.
This commit is contained in:
LamGC 2021-09-10 01:25:57 +08:00
parent d6738d635c
commit b8b2268d2e
Signed by: LamGC
GPG Key ID: 6C5AE2A913941E1D

View File

@ -54,9 +54,11 @@ public final class CommandExecSession implements Closeable {
/**
* 等待程序执行完毕.
* @param timeout 超时时间, 0 为无限等待(单位: 毫秒).
* @return 如果在超时时间内返回, 返回 {@code true}, 超时返回 {@code false}.
*/
public void waitFor(long timeout) {
channelExec.waitFor(EnumSet.of(ClientChannelEvent.EXIT_STATUS, ClientChannelEvent.EXIT_SIGNAL), timeout);
public boolean waitFor(long timeout) {
return !channelExec.waitFor(EnumSet.of(ClientChannelEvent.EXIT_STATUS, ClientChannelEvent.EXIT_SIGNAL), timeout)
.contains(ClientChannelEvent.TIMEOUT);
}
/**