Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion internal/exercises/templates/39_panic/panic_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package exercises
package panicex

import (
"strings"
Expand Down
14 changes: 7 additions & 7 deletions internal/exercises/templates/41_time_delay/time_delay.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,41 +5,41 @@ package timedelay
import "time"

// WaitFor pauses execution until roughly ms milliseconds have passed.
func WaitForTemplate(ms int) {
func WaitFor(ms int) {
// TODO: compute a target time using time.Now().Add and wait until reached
}

// NotifyAfter waits for roughly ms milliseconds then sends true on a channel.
func NotifyAfterTemplate(ms int) chan bool {
func NotifyAfter(ms int) chan bool {
// TODO: start a goroutine that checks time.Now against a target and sends on the channel
return nil
}

// WaitUntil blocks until the provided target time is reached (or returns if in the past).
func WaitUntilTemplate(target time.Time) {
func WaitUntil(target time.Time) {
// TODO: loop until time.Now() is not before target
}

// NotifyAt sends true on a channel when the provided target time is reached.
func NotifyAtTemplate(target time.Time) chan bool {
func NotifyAt(target time.Time) chan bool {
// TODO: return a channel that will receive true when the target time arrives
return nil
}

// ElapsedMillis returns how many milliseconds have passed since t.
func ElapsedMillisTemplate(t time.Time) int64 {
func ElapsedMillis(t time.Time) int64 {
// TODO: use time.Since to compute milliseconds
return 0
}

// WaitForOrTimeout waits for ms milliseconds but returns an error if waiting exceeds timeoutMs.
func WaitForOrTimeoutTemplate(ms int, timeoutMs int) error {
func WaitForOrTimeout(ms int, timeoutMs int) error {
// TODO: compute target and deadline with time.Now().Add and return error on timeout
return nil
}

// ScheduleAfter runs fn after roughly ms milliseconds and returns a channel closed when fn finishes.
func ScheduleAfterTemplate(ms int, fn func()) chan struct{} {
func ScheduleAfter(ms int, fn func()) chan struct{} {
// TODO: start a goroutine that waits until target, runs fn, then closes the done channel
return nil
}
3 changes: 0 additions & 3 deletions internal/exercises/templates/42_wait_group/wait_group.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package waitgroup

import "sync"

// Squares takes a slice of numbers and should return a slice
// containing the square of each number.

Expand All @@ -17,7 +15,6 @@ import "sync"
// 5. Collect all values from the channel into a slice and return it.

func Squares(nums []int) []int {
var wg sync.WaitGroup

// TODO: implement the logic here

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,9 @@ func TestLogProcessor(t *testing.T) {
t.Fatalf("Expected 20 processed logs, got %d", len(results))
}

// With 5 workers processing 20 logs at ~5 microseconds each:
// Sequential would take ~100 microseconds
// Concurrent should take ~20-30 microseconds (4 batches of 5)
if elapsed.Microseconds() > 50 {
// the time taken is flaky, but it should be less than 1.4 seconds
// according observed max value
if elapsed.Microseconds() > 1400 {
t.Errorf("Processing took too long (%v), worker pool may not be working correctly", elapsed)
}
})
Expand Down
Loading