Skip to content

Instantly share code, notes, and snippets.

@dragonsinth
Created February 14, 2020 22:08
Show Gist options
  • Select an option

  • Save dragonsinth/cb7fbf38efbaf3a293eee32d46e81a36 to your computer and use it in GitHub Desktop.

Select an option

Save dragonsinth/cb7fbf38efbaf3a293eee32d46e81a36 to your computer and use it in GitHub Desktop.

Revisions

  1. dragonsinth created this gist Feb 14, 2020.
    25 changes: 25 additions & 0 deletions getfriends_serial.go
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,25 @@
    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 {
    friendIds = append(friendIds, id)
    }
    }

    // Map
    ret := map[string]*User{}
    for _, friendId := range friendIds {
    if friend, err := GetUserProfile(ctx, friendId); err != nil {
    return nil, fmt.Errorf("GetUserProfile %d: %w", friendId, err)
    } else {
    ret[friend.Name] = friend
    }
    }
    return ret, nil
    }