This file contains hidden or 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
| package test; | |
| import com.google.common.collect.MapMaker; | |
| import java.io.ByteArrayOutputStream; | |
| import java.io.IOException; | |
| import java.io.InputStream; | |
| import java.lang.reflect.Constructor; | |
| import java.lang.reflect.Method; | |
| import java.util.concurrent.ConcurrentMap; |
This file contains hidden or 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
| package main | |
| import ( | |
| "context" | |
| "encoding/json" | |
| "fmt" | |
| "io" | |
| "log" | |
| "sync/atomic" | |
| "time" |
This file contains hidden or 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
| func GetFriends(ctx context.Context, user int64) (map[string]*User, error) { | |
| g, ctx := errgroup.WithContext(ctx) | |
| friendIds := make(chan int64) | |
| // Produce | |
| g.Go(func() error { | |
| defer close(friendIds) | |
| for it := GetFriendIds(user); ; { | |
| if id, err := it.Next(ctx); err != nil { | |
| if err == io.EOF { |
This file contains hidden or 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
| select { | |
| case <-ctx.Done(): | |
| return ctx.Err() | |
| case friendIds <- id: | |
| } |
This file contains hidden or 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
| func GetFriends(ctx context.Context, user int64) (map[string]*User, error) { | |
| g, ctx := errgroup.WithContext(ctx) | |
| friendIds := make(chan int64) | |
| // Produce | |
| g.Go(func() error { | |
| defer close(friendIds) | |
| for it := GetFriendIds(user); ; { | |
| if id, err := it.Next(ctx); err != nil { | |
| if err == io.EOF { |
This file contains hidden or 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
| func GetFriends(ctx context.Context, user int64) (map[string]*User, error) { | |
| friendIds := make(chan int64) | |
| // Produce | |
| go func() { | |
| defer close(friendIds) | |
| for it := GetFriendIds(user); ; { | |
| if id, err := it.Next(ctx); err != nil { | |
| if err == io.EOF { | |
| break |
This file contains hidden or 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
| func GetFriends(ctx context.Context, user int64) (map[string]*User, error) { | |
| // Produce | |
| var friendIds []int64 | |
| for it := GetFriendIds(user); ; { | |
| if id, err := it.Next(ctx); err != nil { | |
| if err == io.EOF { | |
| break | |
| } | |
| return nil, fmt.Errorf("GetFriendIds %d: %w", user, err) | |
| } else { |
This file contains hidden or 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
| package main | |
| import ( | |
| "context" | |
| "encoding/base64" | |
| "flag" | |
| "fmt" | |
| "log" | |
| container "google.golang.org/api/container/v1beta1" |
This file contains hidden or 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
| type node struct { | |
| value interface{} // the value of the event (nil until ready) | |
| next *node // the next node in the stream (nil until ready) | |
| ready chan struct{} // a channel whose closure marks readiness | |
| } |
This file contains hidden or 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
| promise := eventStream.Subscribe() | |
| for { | |
| select { | |
| case <-ctx.Done(): | |
| return ctx.Err() | |
| case <-promise.Ready(): | |
| v, nextPromise := promise.Next() | |
| if v == nil { | |
| return nil | |
| } |
OlderNewer