Add solution for Challenge 30 by nzamulov#602
Conversation
WalkthroughAdds a new ContextManager abstraction and a concrete simpleContextManager implementation in a single Go file, providing methods for creating cancellable/timeout contexts, attaching/retrieving values, executing cancellation-aware tasks, waiting for completion, helper functions (SimulateWork, ProcessItems), and a main usage example. Changes
Sequence DiagramsequenceDiagram
participant Main
participant Manager as ContextManager
participant Worker as Task
participant Ctx as context.Context
Main->>Manager: NewContextManager()
Manager-->>Main: manager
Main->>Manager: CreateTimeoutContext(parent, timeout)
Manager->>Ctx: context.WithTimeout(parent, timeout)
Ctx-->>Manager: ctx, cancel
Manager-->>Main: ctx, cancel
Main->>Manager: ExecuteWithContext(ctx, task)
Manager->>Worker: task() (observes ctx)
alt task finishes before cancel
Worker-->>Manager: nil
Manager-->>Main: nil
else canceled or deadline exceeded
Worker-->>Manager: context error
Manager-->>Main: error
end
Main->>Manager: WaitForCompletion(ctx, duration)
Manager-->>Main: nil / timeout error
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Pre-merge checks✅ Passed checks (3 passed)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 5
🧹 Nitpick comments (1)
challenge-30/submissions/nzamulov/solution-template.go (1)
10-29: The ContextManager interface wraps stdlib functions without adding value.Most methods (CreateCancellableContext, CreateTimeoutContext, AddValue) are thin wrappers around
contextpackage functions. This abstraction layer doesn't provide additional functionality and violates YAGNI principles. In production code, prefer using thecontextpackage directly.
Challenge 30 Solution
Submitted by: @nzamulov
Challenge: Challenge 30
Description
This PR contains my solution for Challenge 30.
Changes
challenge-30/submissions/nzamulov/solution-template.goTesting
Thank you for reviewing my submission! 🚀