Giter Club home page Giter Club logo

taskaroo's Introduction

taskaroo

Stable

A Java library that handles execution of tasks. Tasks can be executed sequentially, in parallel, or in any order.

Features

  • Tasks are completely thread safe
  • Tasks can be canceled before they are ran and even while (if supported).
  • Tasks can be invoked synchronously (blocks until result is returned) and can have a timeout.
  • Tasks can be invoked asynchronously (non-blocking)
  • Tasks can be grouped and executed in any order (TaskSet)
  • Tasks can be grouped and executed in insertion order (TaskList)
  • Tasks can be grouped and executed simultaneously (TaskGroup)
  • Tasks can be forked to be ran in a separate context

Documentation

Example

// A task to search a massive haystack for the first occurrence of needle.
public class SearchTask extends Task<Integer> {
    private String needle, haystack;
    public SearchTask(String needle, String haystack) {
        this.needle = needle;
        this.haystack = haystack;
    }
    protected Integer execute() {
        return haystack.indexOf(needle);
    }
}

// Create a service for performing the tasks.
TaskService service = new TaskService();
service.start();

// Create the search task and set the service which will execute it.
SearchTask task = new SearchTask("o", "Hello World");
task.setHandler(service);
// Wait no longer then a second when synchronously invoking.
task.setTimeout(1000);

// Execute the task asynchronously.
task.async(new TaskListener<Integer>() {
    public void onTaskTimeout(Task<Integer> source) {
        // Task timed out (took more than a second).
    }
    public void onTaskSuccess(Task<Integer> source, Integer result) {
        // Task was a success and no errors were thrown.
    }
    public void onTaskFinish(Task<Integer> source) {
        // Task has completed in some manor.
    }
    public void onTaskError(Task<Integer> source, Throwable error) {
        // Task produced an error (NullPointerException?)
    }
    public void onTaskCancel(Task<Integer> source) {
        // Task cancelled before it ever finished.
    }
});

// Execute task synchronously (could timeout if it takes more than a second).
Integer result = task.sync();

// Stop handling tasks.
service.stop();

Builds

Projects using taskaroo:

Dependencies

Testing Examples

taskaroo's People

Contributors

clickermonkey avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.