-
Notifications
You must be signed in to change notification settings - Fork 178
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #105 from lovoo/feature/restartable-views
add restartable view support
- Loading branch information
Showing
9 changed files
with
202 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package goka | ||
|
||
import "sync" | ||
|
||
type once struct { | ||
once sync.Once | ||
err error | ||
} | ||
|
||
// Do runs only once and always return the same error. | ||
func (o *once) Do(f func() error) error { | ||
o.once.Do(func() { o.err = f() }) | ||
return o.err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package goka | ||
|
||
import ( | ||
"errors" | ||
"testing" | ||
|
||
"github.com/facebookgo/ensure" | ||
) | ||
|
||
func TestOnce_Do(t *testing.T) { | ||
var o once | ||
|
||
err := o.Do(func() error { return errors.New("some error") }) | ||
ensure.NotNil(t, err) | ||
|
||
err2 := o.Do(func() error { return nil }) | ||
ensure.NotNil(t, err2) | ||
ensure.DeepEqual(t, err, err2) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.