Skip to content
This repository has been archived by the owner on May 29, 2022. It is now read-only.

Commit

Permalink
async_loop lifetime (arg) update
Browse files Browse the repository at this point in the history
  • Loading branch information
slowcheet4h committed Apr 4, 2021
1 parent efeb789 commit 7c6fd1d
Show file tree
Hide file tree
Showing 20 changed files with 829 additions and 786 deletions.
53 changes: 50 additions & 3 deletions pisi/unitedmeows/meowlib/async/Async.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
import java.util.UUID;

public class Async {

/*TODO: Create ForgettableHashmap and replace this */

private static HashMap<CoID, Task<?>> pointers;

static {
Expand Down Expand Up @@ -64,7 +63,7 @@ public void run() {


public static <X> Future<X> async_w(IAsyncAction action, final long after) {
// change this uuid alternative

final CoID pointer = newPointer();

Future<X> future = new Future<>(pointer);
Expand Down Expand Up @@ -93,11 +92,41 @@ public void run() {
}
}
};
promise.start();

MeowLib.getTaskPool().queue_w(task, repeatDelay);
return promise;
}

/* same as wloop but starts manually */
public static Promise async_wloop_w(IAsyncAction action, final long repeatDelay) {
final Promise promise = new Promise();
Task<?> task = new Task<Object>(action) {
@Override
public void run() {
if (promise.isValid()) {
action.start(null);
MeowLib.getTaskPool().queue_w(this, repeatDelay);
}
}
};

MeowLib.getTaskPool().queue_w(task, repeatDelay);
return promise;
}

public static Promise async_loop(IAsyncAction action, final long repeatDelay, final long lifeTime) {
final Promise promise = async_loop(action, repeatDelay);
async_w((u) -> promise.stop(), lifeTime);
return promise;
}

public static Promise async_loop_w(IAsyncAction action, final long repeatDelay, final long lifeTime) {
final Promise promise = async_loop_w(action, repeatDelay);
async_w((u) -> promise.stop(), lifeTime + repeatDelay);
return promise;
}

public static Promise async_loop(IAsyncAction action, final long repeatDelay) {
final Promise promise = new Promise();
Task<?> task = new Task<Object>(action) {
Expand All @@ -109,6 +138,24 @@ public void run() {
}
}
};
promise.start();

MeowLib.getTaskPool().queue(task);
return promise;
}

/* same as async_loop but starts manually */
public static Promise async_loop_w(IAsyncAction action, final long repeatDelay) {
final Promise promise = new Promise();
Task<?> task = new Task<Object>(action) {
@Override
public void run() {
if (promise.isValid()) {
action.start(null);
MeowLib.getTaskPool().queue_w(this, repeatDelay);
}
}
};

MeowLib.getTaskPool().queue(task);
return promise;
Expand Down
2 changes: 1 addition & 1 deletion pisi/unitedmeows/meowlib/async/BasicTaskPool.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public void workerC() {
TaskWorker freeWorker = new TaskWorker(this);
taskWorkers.add(freeWorker);
freeWorker.startWorker();
} else if (taskWorkers.size() > 3){
} else if (taskWorkers.size() > 6){
for (TaskWorker nWorking : nWorkings) {
taskWorkers.remove(nWorking);
}
Expand Down
28 changes: 14 additions & 14 deletions pisi/unitedmeows/meowlib/async/Result.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package pisi.unitedmeows.meowlib.async;

public class Result<X> {

protected X value;

public Result(X val) {
value = val;
}

public X value() {
return value;
}
}
package pisi.unitedmeows.meowlib.async;

public class Result<X> {

protected X value;

public Result(X val) {
value = val;
}

public X value() {
return value;
}
}
16 changes: 8 additions & 8 deletions pisi/unitedmeows/meowlib/etc/IAction.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package pisi.unitedmeows.meowlib.etc;

import java.util.UUID;

@FunctionalInterface
public interface IAction {
void run() throws Exception;
}
package pisi.unitedmeows.meowlib.etc;

import java.util.UUID;

@FunctionalInterface
public interface IAction {
void run() throws Exception;
}
46 changes: 23 additions & 23 deletions pisi/unitedmeows/meowlib/etc/MLibSetting.java
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
package pisi.unitedmeows.meowlib.etc;


import java.io.Serializable;

public class MLibSetting<X extends Serializable> {

private MLibSettings label;
private X value;

public MLibSetting(MLibSettings label, X value) {
this.label = label;
this.value = value;
}

public X getValue() {
return value;
}

public MLibSettings getLabel() {
return label;
}
}
package pisi.unitedmeows.meowlib.etc;


import java.io.Serializable;

public class MLibSetting<X extends Serializable> {

private MLibSettings label;
private X value;

public MLibSetting(MLibSettings label, X value) {
this.label = label;
this.value = value;
}

public X getValue() {
return value;
}

public MLibSettings getLabel() {
return label;
}
}
56 changes: 28 additions & 28 deletions pisi/unitedmeows/meowlib/etc/Tuple.java
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
package pisi.unitedmeows.meowlib.etc;

public class Tuple<F, S> {

private F first;
private S second;

public Tuple(F first, S second) {
this.first = first;
this.second = second;
}

public F getFirst() {
return first;
}

public S getSecond() {
return second;
}

public void setFirst(F first) {
this.first = first;
}

public void setSecond(S second) {
this.second = second;
}
}
package pisi.unitedmeows.meowlib.etc;

public class Tuple<F, S> {

private F first;
private S second;

public Tuple(F first, S second) {
this.first = first;
this.second = second;
}

public F getFirst() {
return first;
}

public S getSecond() {
return second;
}

public void setFirst(F first) {
this.first = first;
}

public void setSecond(S second) {
this.second = second;
}
}
54 changes: 27 additions & 27 deletions pisi/unitedmeows/meowlib/etc/Tuple3.java
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
package pisi.unitedmeows.meowlib.etc;

public class Tuple3<F, S, T> {

private F first;
private S second;
private T third;


public Tuple3(F first, S second, T third) {
this.first = first;
this.second = second;
this.third = third;
}

public F getFirst() {
return first;
}

public S getSecond() {
return second;
}

public T getThird() {
return third;
}
}
package pisi.unitedmeows.meowlib.etc;

public class Tuple3<F, S, T> {

private F first;
private S second;
private T third;


public Tuple3(F first, S second, T third) {
this.first = first;
this.second = second;
this.third = third;
}

public F getFirst() {
return first;
}

public S getSecond() {
return second;
}

public T getThird() {
return third;
}
}
66 changes: 33 additions & 33 deletions pisi/unitedmeows/meowlib/etc/Tuple4.java
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
package pisi.unitedmeows.meowlib.etc;

public class Tuple4<F, S, T, L> {

private F first;
private S second;
private T third;
private L last;


public Tuple4(F first, S second, T third, L last) {
this.first = first;
this.second = second;
this.third = third;
this.last = last;
}

public F getFirst() {
return first;
}

public S getSecond() {
return second;
}

public T getThird() {
return third;
}

public L getLast() {
return last;
}
}
package pisi.unitedmeows.meowlib.etc;

public class Tuple4<F, S, T, L> {

private F first;
private S second;
private T third;
private L last;


public Tuple4(F first, S second, T third, L last) {
this.first = first;
this.second = second;
this.third = third;
this.last = last;
}

public F getFirst() {
return first;
}

public S getSecond() {
return second;
}

public T getThird() {
return third;
}

public L getLast() {
return last;
}
}
14 changes: 7 additions & 7 deletions pisi/unitedmeows/meowlib/etc/memorable/MemorableElement.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package pisi.unitedmeows.meowlib.etc.memorable;

public class MemorableElement<X> {
public int index;
public X element;
public MemorableTail<X> parentTail;
}
package pisi.unitedmeows.meowlib.etc.memorable;

public class MemorableElement<X> {
public int index;
public X element;
public MemorableTail<X> parentTail;
}
Loading

0 comments on commit 7c6fd1d

Please sign in to comment.