Skip to content

Instantly share code, notes, and snippets.

@jbowa
Created January 18, 2024 11:24
Show Gist options
  • Save jbowa/7b0781919c948a48d20c58498be53abf to your computer and use it in GitHub Desktop.
Save jbowa/7b0781919c948a48d20c58498be53abf to your computer and use it in GitHub Desktop.
Code used during golden hour
package main
import (
"errors"
"fmt"
"sync"
"time"
)
type (
zoomMeeting struct {
// 10 or 11 digits -> Rune -> int32 - Unicode characters
ID int64
// string -> []byte{} -> byte -> uint8 // type byte = uint8 // A, B, C, D etc
Topic string
}
)
func main() {
m := eventRepo()
var wg sync.WaitGroup
errChan := make([]chan error, len(m))
for i := range errChan {
errChan[i] = make(chan error, 1)
}
for i, v := range m {
wg.Add(1)
go func(i int, v zoomMeeting) {
defer wg.Done()
err := zoomValidateHTTP(v)
if err != nil {
errChan[i] <- err
} else {
close(errChan[i])
}
}(i, v)
}
wg.Wait()
for _, ch := range errChan {
if ch != nil {
err, ok := <-ch
if ok {
fmt.Printf("Error %v", err)
}
}
}
}
func zoomValidateHTTP(m zoomMeeting) error {
time.Sleep(3 * time.Second)
fmt.Println("fetched event for ID %v", m.ID)
if m.ID == 5 {
return errors.New("this is some random error")
}
return nil
}
func eventRepo() []zoomMeeting {
var m []zoomMeeting
for i := 0; i < 10; i++ {
m = append(m, zoomMeeting{
ID: int64(i),
Topic: fmt.Sprintf("Topic %v", i),
})
}
return m
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment