Cut out a couple of middlemen
This commit is contained in:
parent
935b7ea5c3
commit
864f371034
|
@ -201,15 +201,6 @@ public class Actor implements Executor {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void execute(Runnable work, Runnable ifNotAlive) {
|
public void execute(Runnable work, Runnable ifNotAlive) {
|
||||||
this.later(0, work, ifNotAlive);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void later(long delayMilliseconds, Runnable work) {
|
|
||||||
this.later(delayMilliseconds, work, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void later(long delayMilliseconds, Runnable work, Runnable ifNotAlive) {
|
|
||||||
if (delayMilliseconds == 0) {
|
|
||||||
{
|
{
|
||||||
WorkItem i = new WorkItem(work, ifNotAlive);
|
WorkItem i = new WorkItem(work, ifNotAlive);
|
||||||
tail.getAndSet(i).set(i);
|
tail.getAndSet(i).set(i);
|
||||||
|
@ -236,6 +227,15 @@ public class Actor implements Executor {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void later(long delayMilliseconds, Runnable work) {
|
||||||
|
this.later(delayMilliseconds, work, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void later(long delayMilliseconds, Runnable work, Runnable ifNotAlive) {
|
||||||
|
if (delayMilliseconds == 0) {
|
||||||
|
this.execute(work, ifNotAlive);
|
||||||
} else {
|
} else {
|
||||||
_scheduledExecutor.schedule(() -> this._performSync(work, ifNotAlive), delayMilliseconds, TimeUnit.MILLISECONDS);
|
_scheduledExecutor.schedule(() -> this._performSync(work, ifNotAlive), delayMilliseconds, TimeUnit.MILLISECONDS);
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,18 +18,21 @@ public class Remote<T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void async(Consumer<T> f) {
|
public void async(Consumer<T> f) {
|
||||||
this.async(0, f);
|
this._actor.execute(() -> f.accept(this._target));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void async(long delayMilliseconds, Consumer<T> f) {
|
public void async(long delayMilliseconds, Consumer<T> f) {
|
||||||
this._actor.later(delayMilliseconds, () -> f.accept(this._target));
|
this._actor.later(delayMilliseconds, () -> f.accept(this._target));
|
||||||
}
|
}
|
||||||
|
|
||||||
public Promise<Object> syncVoid(Consumer<T> f) {
|
public Promise<?> syncVoid(Consumer<T> f) {
|
||||||
return this.syncVoid(0, f);
|
return this.sync((t) -> {
|
||||||
|
f.accept(t);
|
||||||
|
return null;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public Promise<Object> syncVoid(long delayMilliseconds, Consumer<T> f) {
|
public Promise<?> syncVoid(long delayMilliseconds, Consumer<T> f) {
|
||||||
return this.sync(delayMilliseconds, (t) -> {
|
return this.sync(delayMilliseconds, (t) -> {
|
||||||
f.accept(t);
|
f.accept(t);
|
||||||
return null;
|
return null;
|
||||||
|
@ -37,7 +40,11 @@ public class Remote<T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
public<R> Promise<R> sync(Function<T, R> f) {
|
public<R> Promise<R> sync(Function<T, R> f) {
|
||||||
return this.sync(0, f);
|
Promise<R> p = new Promise<>();
|
||||||
|
this._actor.execute(
|
||||||
|
() -> p.resolveWith(f.apply(this._target)),
|
||||||
|
() -> p.rejectWith(this._actor.getExitReason()));
|
||||||
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
public<R> Promise<R> sync(long delayMilliseconds, Function<T, R> f) {
|
public<R> Promise<R> sync(long delayMilliseconds, Function<T, R> f) {
|
||||||
|
|
Loading…
Reference in New Issue