Jump to content

Interrupting main loop


Abuse

Recommended Posts


@@Override

public void onStart() {

ExecutorService executor = Executors.newCachedThreadPool();

executor.submit(() -> {

while (bot.getScriptExecutor().isRunning()) {

if (... condition to interrupt ...) {

bot.getEventExecutor().interrupt();

}

try {

Thread.sleep(100);

} catch (InterruptedException e) {

log(Throwables.getStackTraceAsString(e));

}

}

});

}

@@Override

public int onLoop() {

log("Executing loop");

execute(new Event() {

@@Override

public int execute() {

try {

sleep(10000);

} catch (InterruptedException e) {

setFailed();

}

setFinished();

return -1;

}

});

return statement;

}

Edited by Token
  • Like 3
Link to comment
Share on other sites

@[member='Override']
public void onStart() {
    ExecutorService executor = Executors.newCachedThreadPool();
    executor.submit(() -> {
        while (bot.getScriptExecutor().isRunning()) {
            if (... condition to interrupt ...) {
                bot.getEventExecutor().interrupt();
            }
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
                log(Throwables.getStackTraceAsString(e));
            }
        }
    });
}

@[member='Override']
public int onLoop() {
    log("Executing loop");
    execute(new Event() {
        @[member='Override']
        public int execute() {
            try {
                sleep(10000);
            } catch (InterruptedException e) {
                setFailed();
            }
            setFinished();
            return -1;
        }
    });
    return statement;
}

 

Perfect, exactly what I was looking for!

 

Thank you

 

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...