mirror of
https://github.com/AsamK/signal-cli
synced 2025-08-29 18:40:39 +00:00
Use Duration for timeout
This commit is contained in:
parent
fa3c79828a
commit
71e0c3f80c
4 changed files with 16 additions and 14 deletions
|
@ -17,8 +17,8 @@ import org.slf4j.Logger;
|
|||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.time.Duration;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class ReceiveCommand implements LocalCommand {
|
||||
|
||||
|
@ -59,7 +59,7 @@ public class ReceiveCommand implements LocalCommand {
|
|||
if (timeout < 0) {
|
||||
m.receiveMessages(handler);
|
||||
} else {
|
||||
m.receiveMessages((long) (timeout * 1000), TimeUnit.MILLISECONDS, handler);
|
||||
m.receiveMessages(Duration.ofMillis((long) (timeout * 1000)), handler);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new IOErrorException("Error while receiving messages: " + e.getMessage(), e);
|
||||
|
|
|
@ -42,6 +42,7 @@ import java.io.File;
|
|||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.time.Duration;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
|
@ -50,7 +51,6 @@ import java.util.Map;
|
|||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.stream.Collectors;
|
||||
|
@ -494,11 +494,11 @@ public class DbusManagerImpl implements Manager {
|
|||
|
||||
@Override
|
||||
public void receiveMessages(
|
||||
final long timeout, final TimeUnit unit, final ReceiveMessageHandler handler
|
||||
final Duration timeout, final ReceiveMessageHandler handler
|
||||
) throws IOException {
|
||||
addReceiveHandler(handler);
|
||||
try {
|
||||
Thread.sleep(unit.toMillis(timeout));
|
||||
Thread.sleep(timeout.toMillis());
|
||||
} catch (InterruptedException ignored) {
|
||||
}
|
||||
removeReceiveHandler(handler);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue