[go: up one dir, main page]

Menu

Tree [b712ce] v0.2.2 / async /
 History

HTTPS access


File Date Author Commit
 src 2015-04-21 Daniel Sperry Daniel Sperry [01187e] Changing orbit-async to use orbit-agent-loader.
 README.md 2015-04-19 Joe Hegarty Joe Hegarty [18639d] Update README.md
 pom.xml 2015-04-21 joe@bioware.com joe@bioware.com [b712ce] Version 0.2.2.

Read Me

Orbit Async

Orbit Async implements async-await methods in the JVM. It allows programmers to write asynchronous code in a sequential fashion. It was developed by BioWare, a division of Electronic Arts.

If you're looking for async await on the .NET CLR, see Asynchronous Programming with Async and Await.

Documentation

Documentation is located here.

License

Orbit is licensed under the BSD 3-Clause License.

Simple Examples

With Orbit Tasks

import com.ea.orbit.async.Await;
import static com.ea.orbit.async.Await.await;

public class Page
{
    // has to be done at least once, usually in the main class.
    static { Await.init(); }

    public Task<Integer> getPageLength(URL url)
    {
        Task<String> pageTask = getPage(url);

        // this will never block, it will return a promise
        String page = await(pageTask);

        return Task.fromValue(page.length());
    }
}

Task<Integer> lenTask = getPageLength(new URL("http://example.com"));
System.out.println(lenTask.join());

With CompletableFuture

import com.ea.orbit.async.Async;
import com.ea.orbit.async.Await;
import static com.ea.orbit.async.Await.await;

public class Page
{
    // has to be done at least once, usually in the main class.
    static { Await.init(); }

    // must mark CompletableFuture methods with @Async
    @Async
    public CompletableFuture<Integer> getPageLength(URL url)
    {
        CompletableFuture<String> pageTask = getPage(url);
        String page = await(pageTask);
        return CompletableFuture.completedFuture(page.length());
    }
 }

CompletableFuture<Integer> lenTask = getPageLength(new URL("http://example.com"));
System.out.println(lenTask.join());