Skip to content

Conversation

@stepancheg
Copy link
Contributor

Two patches improving futures.

  • simplify AbstractListenableFuture.executionList initialization
  • Allow null executor in ListenableFuture

Just use CAS loop instead of synchronized and two boolean variables.
executionList = localExecutionList;
executionListInitialized = true;
}
for (;;) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure we need this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure what you meant. Loop is not needed indeed. I've updated the PR.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That was exactly my thought. :)

@slandelle
Copy link
Contributor

Nice catch, thanks! I do have a question though.

It allows execution of future callback in completion thread, and
makes `ListenableFuture` closer to `CompletableFuture` (which allows
`null` executor).

It also saves a little memory in `toCompletableFuture` implementation.
@slandelle slandelle merged commit 8048931 into AsyncHttpClient:master Oct 26, 2016
@stepancheg
Copy link
Contributor Author

Wait!

I made a mistake in addListener:

    @Override
    public ListenableFuture<V> addListener(Runnable listener, Executor exec) {
        if (executionList == null) {
            ExecutionList.executeListener(listener, exec); // <-- HERE
            return this;
        }

        executionList().add(listener, exec);
        return this;
    }

Revert it please.

@stepancheg
Copy link
Contributor Author

Going to submit alternative patch.

@stepancheg
Copy link
Contributor Author

Revert for the first part is #1288, better patch for the first part is #1287.

@slandelle
Copy link
Contributor

@stepancheg I deleted the commit

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants