Skip to content

Comments

Add ReusableBlockingVariable to allow reset the state of the variable…#721

Closed
guenhter wants to merge 1 commit intospockframework:masterfrom
guenhter:master
Closed

Add ReusableBlockingVariable to allow reset the state of the variable…#721
guenhter wants to merge 1 commit intospockframework:masterfrom
guenhter:master

Conversation

@guenhter
Copy link

@guenhter guenhter commented Apr 18, 2017

Often it's needed to use the same BlockingVariable again but reset it. E.g. when the variable is used for Messaging and is contained in a consumer. Than it isn't always that easy to replace the existing variable with a new instance. So I added a simple reset method which resets the value and the CountDownLatch of the BlockingVariable.

This also was suggested in
#312

So it is now possible to do:

BlockingVariable<String> b = ...
// do something async with the var

when:
sender.send("val1")
then:
b.get() == "val1"

when:
b.reset()
sender.send("val2")
then:
b.get() == "val2"

when:
b.reset()
sender.error();
b.get()
then:
thrown(SpockTimeoutError)

(I know, this samples can be split up to own tests, but there are other circumstances where such cases are needed)


This change is Reviewable

@codecov
Copy link

codecov bot commented Apr 18, 2017

Codecov Report

Merging #721 into master will increase coverage by 0.02%.
The diff coverage is 92.85%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master     #721      +/-   ##
============================================
+ Coverage     73.16%   73.18%   +0.02%     
- Complexity     3088     3094       +6     
============================================
  Files           341      342       +1     
  Lines          9639     9653      +14     
  Branches       1201     1201              
============================================
+ Hits           7052     7065      +13     
- Misses         2144     2145       +1     
  Partials        443      443
Impacted Files Coverage Δ Complexity Δ
...ock/util/concurrent/ReuseableBlockingVariable.java 92.85% <92.85%> (ø) 6 <6> (?)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e9d7edc...d52ea1b. Read the comment docs.

@leonard84
Copy link
Member

FYI, we won't merge any new features until 1.1 is released.

@guenhter guenhter closed this Jun 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants