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

Modified blocking return to have more intuitive behavior #19

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

chentom88
Copy link

Instead of methods blocking by default, changed blocking return behavior to require user activation. Also created an additional channel that can be used to unblock a mock method call once it has been set to blocked.

@nelsam
Copy link
Owner

nelsam commented Feb 27, 2016

That's interesting. Give me a bit to think on it, but I like the idea.

@poy
Copy link
Collaborator

poy commented Feb 27, 2016

Could we instead take advantage of the Called channel? For instance we could fill it with a helper in eachers (much like AlwaysReturn())?

@nelsam
Copy link
Owner

nelsam commented Apr 3, 2016

@apoydence: How would that work? Do you mean something like this?

func BlockSend(calledField *chan bool) chan<- struct{} {
    oldChan := *calledField
    newChan := make(chan bool)
    *calledField = newChan
    signalUnblock := make(chan struct{})
    go func() {
        <-signalUnblock
        v := <-newChan
        oldChan <- v
        *calledField = oldChan
    }()
    return signalUnblock
}

http://play.golang.org/p/LBRhQFTdKq

There are obviously data races there, but the basic idea is to re-assign the FooCalled channel with a channel that has no buffer. The send operation will then block until a value is received from the new FooCalled channel. The helper sets up a goroutine to take care of this as soon as signalUnblock gets closed or has a value sent to it.

It would require a change to hel's mocks, too, to defer the FooCalled <- true call (or at least execute it after sending on the Input channels), but that's not a big deal.

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.

3 participants