Skip to content

feat: adding stop() method #100

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 13 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public class DiscordRequestDispatcher implements Runnable {
private static final Logger LOGGER = LogManager.getLogger();
private final BlockingQueue<DiscordRequestBuilder> queue;
private final String botToken;
private boolean appIsActive;
private int numberOfRequestsSent;
private long timeSinceLastRequest;

Expand All @@ -29,6 +30,7 @@ public DiscordRequestDispatcher(String botToken) {
this.queue = new LinkedBlockingQueue<>();
this.numberOfRequestsSent = 0;
this.timeSinceLastRequest = 0;
this.appIsActive = true;
}

public DiscordResponseFuture queue(DiscordRequest discordRequest) {
Expand All @@ -39,7 +41,8 @@ public DiscordResponseFuture queue(DiscordRequest discordRequest) {

@Override
public void run() {
while (true) {

while (appIsActive) {
long currentTime = System.currentTimeMillis();
long elapsed = currentTime - timeSinceLastRequest;

Expand Down Expand Up @@ -128,4 +131,8 @@ private static String[] headerMapToStringArr(Map<String, Object> headers) {
.toList()
.toArray(new String[0]);
}

public void setAppIsActive(boolean appIsActive) {
this.appIsActive = appIsActive;
}
}
2 changes: 2 additions & 0 deletions core/src/main/java/com/javadiscord/jdi/core/Discord.java
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,8 @@ public void stop() {
EXECUTOR.shutdownNow();
Thread.currentThread().interrupt();
}

discordRequestDispatcher.setAppIsActive(false);
}

public void startWithoutGatewayEvents() {
Expand Down