Created
January 18, 2024 11:24
-
-
Save jbowa/7b0781919c948a48d20c58498be53abf to your computer and use it in GitHub Desktop.
Code used during golden hour
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
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