-
Notifications
You must be signed in to change notification settings - Fork 229
TaskBuilder
Jesse Boyd edited this page Nov 1, 2016
·
4 revisions
The TaskBuilder simplifies creating sequential sync/async tasks. https://github.com/boy0001/FastAsyncWorldedit/blob/master/core/src/main/java/com/boydti/fawe/util/task/TaskBuilder.java
- sync([Runnable|ReturnTask|ReceiveTask|Task]) - Run a task on the main thread
- async([Runnable|ReturnTask|ReceiveTask|Task]) - Run a task off the main thread
- delay([int|DelayedTask]) - Delay the next task by a number of ticks
- syncParallel([Runnable|ReturnTask|ReceiveTask|Task]) - Run all the next syncParallel tasks in parallel
- asyncParallel([Runnable|ReturnTask|ReceiveTask|Task]) - Run all the next asyncParallel tasks in parallel
- syncWhenFree([SplitTask|ReturnTask|ReceiveTask|Task]) - Run a task when there's free time on the main thread
- abortIfTrue(Task<Boolean,Object>) - Abort all tasks if true
- build() - Starts execution
- buildAsync() - Starts execution from an async thread
Just prints the number 6
new TaskBuilder()
.async((ReturnTask<Integer>) () -> 5 + 1)
.sync((ReceiveTask) input -> System.out.println(input))
.build();
Split up a task and run it when the main thread is free.
// In reality you'd use one of EditSession, AsyncWorld, FaweQueue instead.
// But this is just an example of how you can split up a task with the FAWE API
final World world = Bukkit.getWorld("world");
new TaskBuilder()
// Execution will be split into multiple 20ms tasks
.syncWhenFree(new TaskBuilder.SplitTask(20) {
@Override
public Object exec(Object previous) {
for (int x = 0; x < 100; x++) {
for (int y = 0; y < 100; y++) {
for (int z = 0; z < 100; z++) {
world.getBlockAt(x, y, z).setType(Material.STONE);
// FAWE will use this point to split the task
// You can have multiple split points
split();
}
}
}
// We don't really need the result for any next tasks
return null;
}
})
.build();
The TaskBuilder extends Metadatable, so you can use it to store temporary data: https://github.com/boy0001/FastAsyncWorldedit/blob/master/core/src/main/java/com/boydti/fawe/object/Metadatable.java
final TaskBuilder task = new TaskBuilder();
task.sync(() -> {
task.setMeta("blah", 5);
return task.<Integer>getMeta("blah") + 56;
});
This wiki is outdated, move to https://github.com/IntellectualSites/FastAsyncWorldEdit-Documentation/
This Wiki is for Legacy Versions (1.8 - 1.12.2). Check here for 1.13+ versions: https://github.com/IntellectualSites/FastAsyncWorldEdit-Documentation/