-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add subscription/channel; notes about CORS
- Loading branch information
thisisaaronland
committed
May 26, 2021
1 parent
852cd46
commit cc6bcda
Showing
2 changed files
with
39 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package subscription | ||
|
||
import ( | ||
"context" | ||
) | ||
|
||
type ChannelSubscription struct { | ||
Subscription | ||
channel chan string | ||
} | ||
|
||
func NewChannelSubscriptionWithChannel(ctx context.Context, ch chan string) (Subscription, error) { | ||
|
||
sub := &ChannelSubscription{ | ||
channel: ch, | ||
} | ||
|
||
return sub, nil | ||
} | ||
|
||
func (sub *ChannelSubscription) Start(ctx context.Context, messages_ch chan string) error { | ||
|
||
for { | ||
select { | ||
case <-ctx.Done(): | ||
return nil | ||
case msg := <-sub.channel: | ||
messages_ch <- msg | ||
} | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (sub *ChannelSubscription) Close() error { | ||
return nil | ||
} |