Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Checkpoint awaitability #24

Open
vietj opened this issue Jan 19, 2018 · 12 comments
Open

Checkpoint awaitability #24

vietj opened this issue Jan 19, 2018 · 12 comments

Comments

@vietj
Copy link
Member

vietj commented Jan 19, 2018

It's often convenient to use a checkpoint as latch to yield the main thread when a condition is met:

Checkpoint checkpoint = ctx.checkpoint();
webClient(callback -> {
  checkpoint.flag();
});

// Await until the checkpoint si met 
// we are on the JUnit thread, so it's ok and very convenient
checkpoint.await();
@jponge
Copy link
Member

jponge commented Jan 22, 2018

Should we recommend that over java.util.concurrent classes?

I see the point of your proposal, but I'm wondering if we should mix concerns or not.

@vietj
Copy link
Member Author

vietj commented Jan 22, 2018

are you thinking of CountDownLatch ?

@vietj
Copy link
Member Author

vietj commented Jan 22, 2018

It can also be seen as a CompletionStage as well

@vietj
Copy link
Member Author

vietj commented Jan 22, 2018

imho just await is fine, CompletionStage has other purpose and CountDownLatch is a read/write interface (i.e if you have it you can count() and (which is what flag() does more or less)

@jponge
Copy link
Member

jponge commented Jan 22, 2018

Yeah I was thinking about a latch

@vietj
Copy link
Member Author

vietj commented Jan 22, 2018

we could think of Checkpoint to be a class an extend the latch, I'm not sure it would buy anything as it's quite a minimalistic API.

@jponge
Copy link
Member

jponge commented Jan 22, 2018

I'd rather compose than extend 😉

@jponge
Copy link
Member

jponge commented Jan 22, 2018

So yeah let's think about await

@vietj
Copy link
Member Author

vietj commented Jan 22, 2018

it was not clear if you meant about API reuse or code reuse

it would be great also to clarify that await should throw an exception when the context fails so basically under the hood it would rather be a CompletableFuture that is completed when the checkpoint is completed and completed exceptionally when its context fails.

@vietj
Copy link
Member Author

vietj commented Jan 22, 2018

you can call it awaitSuccess :-)

@cvgaviao
Copy link

cvgaviao commented Nov 21, 2019

@jponge , there was any progress on this?

Btw, is there any alternative in order to prevent the test method in main thread, other than Thread.sleep(), to finish while an async procedure are being executed?

@jponge
Copy link
Member

jponge commented Dec 4, 2019

@cvgaviao The test method will always execute from the main thread.

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

No branches or pull requests

3 participants