All Projects → electronicarts → Ea Async

electronicarts / Ea Async

Licence: other
EA Async implements async-await methods in the JVM.

Programming Languages

java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to Ea Async

Aiormq
Pure python AMQP 0.9.1 asynchronous client library
Stars: ✭ 112 (-89.68%)
Mutual labels:  async, asynchronous, async-await
Tascalate Concurrent
Implementation of blocking (IO-Bound) cancellable java.util.concurrent.CompletionStage and related extensions to java.util.concurrent.ExecutorService-s
Stars: ✭ 144 (-86.73%)
Mutual labels:  async, asynchronous, concurrency
Async Backplane
Simple, Erlang-inspired fault-tolerance framework for Rust Futures.
Stars: ✭ 113 (-89.59%)
Mutual labels:  async, asynchronous, async-await
Radon
Object oriented state management solution for front-end development.
Stars: ✭ 80 (-92.63%)
Mutual labels:  async, asynchronous, async-await
Drone Core
The core crate for Drone, an Embedded Operating System.
Stars: ✭ 263 (-75.76%)
Mutual labels:  async, asynchronous, concurrency
Drone
CLI utility for Drone, an Embedded Operating System.
Stars: ✭ 114 (-89.49%)
Mutual labels:  async, asynchronous, concurrency
Rubico
[a]synchronous functional programming
Stars: ✭ 133 (-87.74%)
Mutual labels:  async, asynchronous, async-await
Asyncorm
Fully Async ORM inspired in django's
Stars: ✭ 182 (-83.23%)
Mutual labels:  async, asynchronous, async-await
Shift
Light-weight EventKit wrapper.
Stars: ✭ 31 (-97.14%)
Mutual labels:  asynchronous, concurrency, async-await
Coerce Rs
Coerce - an asynchronous (async/await) Actor runtime and cluster framework for Rust
Stars: ✭ 231 (-78.71%)
Mutual labels:  async, asynchronous, async-await
P Map
Map over promises concurrently
Stars: ✭ 639 (-41.11%)
Mutual labels:  async, concurrency, async-await
Promise Fun
Promise packages, patterns, chat, and tutorials
Stars: ✭ 3,779 (+248.29%)
Mutual labels:  async, concurrency, async-await
Swiftcoroutine
Swift coroutines for iOS, macOS and Linux.
Stars: ✭ 690 (-36.41%)
Mutual labels:  async, asynchronous, async-await
Vue Loadable
⏳ Improve your loading state control with pretty simple methods and helpers.
Stars: ✭ 23 (-97.88%)
Mutual labels:  async, asynchronous
Then
🎬 Tame async code with battle-tested promises
Stars: ✭ 908 (-16.31%)
Mutual labels:  async, async-await
Chili
Chili: HTTP Served Hot
Stars: ✭ 7 (-99.35%)
Mutual labels:  async, asynchronous
Request.swift
A tiny HTTP client written in swift. URLSession alternative
Stars: ✭ 14 (-98.71%)
Mutual labels:  async, asynchronous
Blockly Gamepad
A Blockly extension designed to develop games (made with love ❤)
Stars: ✭ 18 (-98.34%)
Mutual labels:  async, asynchronous
Parallel Ssh
Asynchronous parallel SSH client library.
Stars: ✭ 864 (-20.37%)
Mutual labels:  async, asynchronous
Pulsar
Fibers, Channels and Actors for Clojure
Stars: ✭ 885 (-18.43%)
Mutual labels:  concurrency, jvm

EA Async

Release Maven Central Javadocs Build Status

EA Async implements Async-Await methods in the JVM. It allows programmers to write asynchronous code in a sequential fashion.

It is heavily inspired by Async-Await on the .NET CLR, see Asynchronous Programming with Async and Await for more information.

Who should use it?

EA Async should be used to write non-blocking asynchronous code that makes heavy use of CompletableFutures or CompletionStage. It improves scalability by freeing worker threads while your code awaits other processes; And improves productivity by making asynchronous code simpler and more readable.

Developer & License

This project was developed by Electronic Arts and is licensed under the BSD 3-Clause License.

Examples

With EA Async

import static com.ea.async.Async.await;
import static java.util.concurrent.CompletableFuture.completedFuture;

public class Store
{
    public CompletableFuture<Boolean> buyItem(String itemTypeId, int cost)
    {
        if(!await(bank.decrement(cost))) {
            return completedFuture(false);
        }
        await(inventory.giveItem(itemTypeId));
        return completedFuture(true);
    }
}

In this example Bank.decrement returns CompletableFuture<Boolean> and Inventory.giveItem returns CompletableFuture<String>

EA Async rewrites the calls to Async.await making your methods non-blocking.

The methods look blocking but are actually transformed into asynchronous methods that use CompletableFutures to continue the execution as intermediary results arrive.

Without EA Async

This is how the first example looks without EA Async. It is a bit less readable.

import static java.util.concurrent.CompletableFuture.completedFuture;

public class Store
{
    public CompletableFuture<Boolean> buyItem(String itemTypeId, int cost)
    {
        return bank.decrement(cost)
            .thenCompose(result -> {
                if(!result) {
                    return completedFuture(false);
                }
                return inventory.giveItem(itemTypeId).thenApply(res -> true);
            });
    }
}

This is a small example... A method with a few more CompletableFutures can look very convoluted.

EA Async abstracts away the complexity of the CompletableFutures.

With EA Async (2)

So you like CompletableFutures? Try converting this method to use only CompletableFutures without ever blocking (so no joining):

import static com.ea.async.Async.await;
import static java.util.concurrent.CompletableFuture.completedFuture;

public class Store
{
    public CompletableFuture<Boolean> buyItem(String itemTypeId, int cost)
    {
        if(!await(bank.decrement(cost))) {
            return completedFuture(false);
        }
        try {
            await(inventory.giveItem(itemTypeId));
            return completedFuture(true);
        } catch (Exception ex) {
            await(bank.refund(cost));
            throw new AppException(ex);
        }
    }
}

Got it? Send it to us. It probably looks ugly...

Getting started

EA Async currently supports JDK 8-10.

It works with Java and Scala and should work with most JVM languages. The only requirement to use EA Async is that must be used only inside methods that return CompletableFuture, CompletionStage, or subclasses of CompletableFuture.

Using with maven

<dependency>
    <groupId>com.ea.async</groupId>
    <artifactId>ea-async</artifactId>
    <version>1.2.3</version>
</dependency>

Gradle

'com.ea.async:ea-async:1.2.3'

Instrumenting your code

Option 1 - JVM parameter

Start your application with an extra JVM parameter: -javaagent:ea-async-1.2.3.jar

 java -javaagent:ea-async-1.2.3.jar -cp your_claspath YourMainClass args...

It's recommended to add this as a default option to launchers in IntelliJ projects that use ea-async.

Option 2 - Runtime

On your main class or as early as possible, call at least once:

Async.init();

Provided that your JVM has the capability enabled, this will start a runtime instrumentation agent. If you forget to invoke this function, the first call to await will initialize the system (and print a warning).

This is a solution for testing and development, it has the least amount of configuration. It might interfere with JVM debugging. This alternative is present as a fallback.

Option 3 - Run instrumentation tool

The ea-async-1.2.3.jar is a runnable jar that can pre-instrument your files.

Usage:

java -cp YOUR_PROJECT_CLASSPATH -jar ea-async-1.2.3.jar classDirectory

Example:

java -cp guava.jar;commons-lang.jar  -jar ea-async-1.2.3.jar target/classes

After that all the files in target/classes will have been instrumented. There will be no references to Async.await and Async.init left in those classes.

Option 4 - Build time instrumentation, with Maven - Preferred

Use the ea-async-maven-plugin. It will instrument your classes in compile time and remove all references to Async.await and Async.init().

With build time instrumentation your project users won't need to have EA Async in their classpath unless they also choose to use it. This means that EA Async does not need to be a transitive dependency.

This is the best option for libraries and maven projects.

<build>
    <plugins>
        <plugin>
            <groupId>com.ea.async</groupId>
            <artifactId>ea-async-maven-plugin</artifactId>
            <version>1.2.3</version>
            <executions>
                <execution>
                    <goals>
                        <goal>instrument</goal>
                        <goal>instrument-test</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].