-
Notifications
You must be signed in to change notification settings - Fork 338
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
302 additions
and
30 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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package rxgo | ||
|
||
import "context" | ||
|
||
type OptionalSingle interface { | ||
Iterable | ||
} | ||
|
||
func newOptionalSingleFromOperator(ctx context.Context, source Single, nextFunc Operator, errFunc Operator) OptionalSingle { | ||
next := make(chan Item) | ||
|
||
stop := func() {} | ||
go func() { | ||
for { | ||
select { | ||
case <-ctx.Done(): | ||
close(next) | ||
return | ||
case i, ok := <-source.Observe(): | ||
if !ok { | ||
close(next) | ||
return | ||
} | ||
if i.IsError() { | ||
errFunc(i, next, stop) | ||
close(next) | ||
return | ||
} else { | ||
nextFunc(i, next, stop) | ||
close(next) | ||
return | ||
} | ||
} | ||
} | ||
}() | ||
|
||
return &optionalSingle{ | ||
iterable: newChannelIterable(next), | ||
} | ||
} | ||
|
||
type optionalSingle struct { | ||
iterable Iterable | ||
} | ||
|
||
func (o *optionalSingle) Observe() <-chan Item { | ||
return o.iterable.Observe() | ||
} |
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,13 @@ | ||
package rxgo | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
) | ||
|
||
func Test_OptionalSingle_Observe(t *testing.T) { | ||
os := FromItem(FromValue(1)).Filter(context.Background(), func(i interface{}) bool { | ||
return i == 1 | ||
}) | ||
AssertOptionalSingle(context.Background(), t, os, HasValue(1), HasNotRaisedError()) | ||
} |
Oops, something went wrong.