Sobes.tech
Junior — Senior
52

Какой вывод появится в консоли у программы №62

Компании, где спрашивали:

Mail.ruMail.ru
Условие задачи

Определите, какой текст будет напечатан в консоли после выполнения следующей Go‑программы:

import ("fmt"
        "time"
        "context"
        "math/rand"
        )

func main() {
    fmt.Println(Do(context.Background(), []User{{"aaa"}, {"bbb"}, {"ccc"},{"ddd"},{"eee"}}))
}

type User struct {
    Name string
}

func fetchbyName(ctx context.Context, userName string) (int, error) {
    
    time.Sleep( 10 * time.Millisecond)
    return rand.Int() % 100000, nil
}

func Do(ctx context.Contextm users []User) (map[string]int, error){
    collected := make(map[string]int)
    for _, u := range users {
        userID, err := fetchByName(ctx, u.Name)
        if err != nil {
            return collected, err
            }   
        collected [u.Name] = userId
        }
    
    return collected, nil
}