question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Repeat Task until Condition is met

See original GitHub issue

It would be nice to have repeating tasks in the chain. something like this:

newChain().repeat(c-> c.repeat(c->c.delay(10, TimeUnit.SECONDS).sync(this::updateSigns),6).async(this::updateDB),-1)

would do something like this

while(true){
   for(int i = 0;i<6;i++){
       wait(10, second)
       (sync) updateSigns();
   }
   (async)updateDB();
}

(repeat would take a lambda that does stuff with a new chain that will be executed every time repeat is called) Don’t really know if the way I outlined that api is a good thing to do something like that, but I think the general concept of repeating some parts of a chain n (or -1 for endless) times.

Issue Analytics

  • State:open
  • Created 7 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
aikarcommented, Feb 5, 2017

Oh I just noticed the infinite loop outer layer.

That’s not something i want to do with TC, as TC needs the ability to shut down, and there’s no clear way to define how to shut that down.

Thats something easy to just wrap in Bukkits repeating task outer wrapper, then TC control the inner actions.

1reaction
aikarcommented, Feb 5, 2017

This would have to look like there’s 2 things really being asked for here.

  1. the ability to call something like .chain((c) -> { }) that allows you to insert tasks into the chain as part of a callback, which would have to execute IMMEDIATELY to build the chain.

So that design isn’t good, it would need to be:

otherChain = TaskChain.newChain()/*some other steps and don't call execute*/;

TaskChain.newChain().import(otherChain);

So TC can read the tasks out of that and clone them into this one;

Then the 2nd request is, a way to say “run this sequence of tasks X times”

I feel like the repeating part is unnecessary as it can be calculated easily by the caller as:

TaskChain chain = TaskChain.newChain();
for (int i = 0; i < 6; i++) {
    chain.import(otherChain); // or could be chain.sync(this.updateDB); to make this template not even needed.
    chain.delay(10, TimeUnit.SECONDS);
}
chain.async(this::updateDB).execute();
chain.execute();

So yeah i don’t see repeating as a beneficial API. But using another chain as a template, maybe so.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to repeat loop until condition is met? While or For Loop?
I wanted to create a loop until a certain condition is met, for example lets say I have constant x, that is included...
Read more >
Repeat/Until Block Loops - Elements Docs
Repeat /Until Block Loops. The repeat / until loop is a loop that executes a block of statements repeatedly, until a given condition...
Read more >
Ansible Retry Examples - Retry a task until condition met
Ansible Retry until can rerun the task only until the defined number of retries. It cannot run the task forever until the condition...
Read more >
Run a repeating task until a condition is met - SpigotMC
Hey! I was wondering how I would run a task over and over, interval needs to be fast, until a condition is met?...
Read more >
Easily Repeat Tasks Using Loops - Learn Python Basics
There are also times when the number of repetitions does not matter, and you want to repeat the code until a certain condition...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found