Skip to content

Says "the method invoking await must return a CompletableFuture" but it does already #34

@DidierLoiseau

Description

@DidierLoiseau

If you forget to instrument the code, the wrong warning message is printed:

WARN com.ea.async.Async - Warning: Illegal call to await, the method invoking await must return a CompletableFuture

instead of

Warning: Illegal call to await, static { Async.init(); } must be added to the main program class and the method invoking await must return a CompletableFuture

As shown by the following simple example:

import java.util.concurrent.CompletableFuture;

import com.ea.async.Async;

public class EAsyncTest {

	static CompletableFuture<String> convert(CompletableFuture<?> future) {
		Object result = Async.await(future);
		return CompletableFuture.completedFuture(result.toString());
	}

	public static void main(String[] args) {
		convert(new CompletableFuture<>());
	}
}

This is because calling InitializeAsync.isRunning() triggers the class initialization, and only enters that method once isRunning = true. The only ways to have isRunning() returning false is if either the initialization crashes or if called from multiple threads.

In addition, I think it would be better to throw an exception than calling join(). In the above example this causes a deadlock, and you don't know which method it is referring to.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions