diff --git a/context_handler.go b/context_handler.go new file mode 100644 index 0000000..d9692a8 --- /dev/null +++ b/context_handler.go @@ -0,0 +1,18 @@ +package main + +import ( + "context" + "fmt" + "time" +) + +func FetchRiwayatKursus(ctx context.Context) error { + select { + case <-time.After(2 * time.Second): // simulasi lama fetch + userID := ctx.Value("UserID").(string) + fmt.Println("Riwayat kursus untuk user:", userID) + return nil + case <-ctx.Done(): + return ctx.Err() + } +} diff --git a/poll_worker.go b/poll_worker.go new file mode 100644 index 0000000..146ca03 --- /dev/null +++ b/poll_worker.go @@ -0,0 +1,13 @@ +package main + +import ( + "fmt" + "time" +) + +func PollJobWorker(id int, jobs <-chan int) { + for job := range jobs { + fmt.Printf("Worker %d: memproses poll job %d\n", id, job) + time.Sleep(50 * time.Millisecond) + } +} diff --git a/worker.go b/worker.go new file mode 100644 index 0000000..07f88bb --- /dev/null +++ b/worker.go @@ -0,0 +1,14 @@ +package main + +import ( + "fmt" + "sync" + "time" +) + +func ProsesSertifikasi(userID int, wg *sync.WaitGroup) { + defer wg.Done() + fmt.Printf("User %d: mulai proses sertifikasi...\n", userID) + time.Sleep(200 * time.Millisecond) // simulasi proses + fmt.Printf("User %d: sertifikasi selesai!\n", userID) +}