Skip to content

Conversation

@MuraliMohan-2000
Copy link
Contributor

Challenge 30 Solution

Submitted by: @MuraliMohan-2000
Challenge: Challenge 30

Description

This PR contains my solution for Challenge 30.

Changes

  • Added solution file to challenge-30/submissions/MuraliMohan-2000/solution-template.go

Testing

  • Solution passes all test cases
  • Code follows Go best practices

Thank you for reviewing my submission! 🚀

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 18, 2026

Walkthrough

Introduces a new context management abstraction in a solution template file. Defines a ContextManager interface with six methods for creating contexts, managing values, and executing tasks with context awareness. Provides a concrete simpleContextManager implementation, helper utilities for simulating work and processing items with cancellation support, and sample usage in main().

Changes

Cohort / File(s) Summary
Context Management Interface and Implementation
challenge-30/submissions/MuraliMohan-2000/solution-template.go
Introduces ContextManager interface with methods for creating cancellable/timeout contexts, managing context values, and executing tasks. Implements concrete simpleContextManager type with NewContextManager() constructor. Helper functions SimulateWork() and ProcessItems() provide context-aware work simulation and batch processing with cancellation handling. Includes main() scaffold demonstrating usage. Note: Several methods contain placeholder panics indicating incomplete implementation.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: adding a solution file for Challenge 30, and clearly identifies the contributor.
Description check ✅ Passed The description is directly related to the changeset, providing context about the Challenge 30 submission and indicating testing and code quality checks were performed.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Fix all issues with AI agents
In `@challenge-30/submissions/MuraliMohan-2000/solution-template.go`:
- Around line 23-25: The ExecuteWithContext implementation currently spawns a
goroutine for task func() error which cannot observe cancellation; change the
task signature to task func(context.Context) error in the interface and all call
sites, modify the ExecuteWithContext method to call task(ctx) (not task()) so
the task can inspect ctx.Done() and return promptly on cancellation, and update
any related tests/implementations that implement ExecuteWithContext to accept
and forward the context.
- Around line 38-45: Several methods (CreateCancellableContext,
CreateTimeoutContext, AddValue, GetValue, ExecuteWithContext, WaitForCompletion,
SimulateWork, and ProcessItems) contain unreachable panic("implement me")
statements immediately after return statements which causes Go compile errors;
remove those trailing panic calls so the function returns are the final
statements (e.g., delete the panic("implement me") line in
CreateCancellableContext that follows the return from
context.WithCancel(parent)) and ensure no other methods in the file contain
return-followed-by-panic patterns.
🧹 Nitpick comments (1)
challenge-30/submissions/MuraliMohan-2000/solution-template.go (1)

55-60: Use typed context keys to avoid collisions.

Using plain string keys risks collisions across packages and violates the usual context.WithValue guidance. Define a private key type and constants, then use those keys in AddValue and main.

🔐 Example adjustment
// near top-level
type ctxKey string

const (
	ctxKeyUser      ctxKey = "user"
	ctxKeyRequestID ctxKey = "requestID"
)
-ctx = cm.AddValue(ctx, "user", "alice")
-ctx = cm.AddValue(ctx, "requestID", "12345")
+ctx = cm.AddValue(ctx, ctxKeyUser, "alice")
+ctx = cm.AddValue(ctx, ctxKeyRequestID, "12345")

Also applies to: 161-163

Comment on lines +23 to +25
// Execute a task with context cancellation support
ExecuteWithContext(ctx context.Context, task func() error) error

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

cd challenge-30/submissions/MuraliMohan-2000 && cat -n solution-template.go | head -100

Repository: RezaSi/go-interview-practice

Length of output: 4208


Context cancellation doesn't reach the task function.

ExecuteWithContext returns on ctx.Done(), but the task keeps running in its goroutine because it never receives the context. The task function signature func() error doesn't accept a context parameter, so it has no way to check for cancellation or respond to it. This defeats the purpose of context cancellation and can cause side effects to continue after the function returns.

Fix: Change the task signature to accept context: task func(context.Context) error, and pass it when calling the task.

🤖 Prompt for AI Agents
In `@challenge-30/submissions/MuraliMohan-2000/solution-template.go` around lines
23 - 25, The ExecuteWithContext implementation currently spawns a goroutine for
task func() error which cannot observe cancellation; change the task signature
to task func(context.Context) error in the interface and all call sites, modify
the ExecuteWithContext method to call task(ctx) (not task()) so the task can
inspect ctx.Done() and return promptly on cancellation, and update any related
tests/implementations that implement ExecuteWithContext to accept and forward
the context.

Comment on lines +38 to +45
// CreateCancellableContext creates a cancellable context
func (cm *simpleContextManager) CreateCancellableContext(parent context.Context) (context.Context, context.CancelFunc) {
// TODO: Implement cancellable context creation
// Hint: Use context.WithCancel(parent)

return context.WithCancel(parent)
panic("implement me")
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Check if the file exists and examine lines 38-45
if [ -f "challenge-30/submissions/MuraliMohan-2000/solution-template.go" ]; then
  echo "=== File content (lines 30-50) ==="
  sed -n '30,50p' "challenge-30/submissions/MuraliMohan-2000/solution-template.go" | cat -n
else
  echo "File not found at expected path"
  # Try to find it
  find . -name "solution-template.go" -type f 2>/dev/null | head -5
fi

Repository: RezaSi/go-interview-practice

Length of output: 1080


🏁 Script executed:

#!/bin/bash
# Search for all panic statements in the file
echo "=== All panic statements in the file ==="
rg "panic\(" "challenge-30/submissions/MuraliMohan-2000/solution-template.go" -n -B 2 -A 0

Repository: RezaSi/go-interview-practice

Length of output: 718


🏁 Script executed:

#!/bin/bash
# Check the full context of functions that may have return+panic patterns
echo "=== All function definitions and their return statements ==="
rg "^func|return|panic" "challenge-30/submissions/MuraliMohan-2000/solution-template.go" -n

Repository: RezaSi/go-interview-practice

Length of output: 1661


Remove unreachable panic statements—Go compiler rejects this code.

Unreachable code after return causes compilation failure. This pattern appears in 8 methods throughout the file: CreateCancellableContext, CreateTimeoutContext, AddValue, GetValue, ExecuteWithContext, WaitForCompletion, SimulateWork, and ProcessItems. Delete all panic("implement me") lines that follow return statements.

Example fix for CreateCancellableContext (apply to all affected methods)
 func (cm *simpleContextManager) CreateCancellableContext(parent context.Context) (context.Context, context.CancelFunc) {
 	// TODO: Implement cancellable context creation
 	// Hint: Use context.WithCancel(parent)
 
 	return context.WithCancel(parent)
-	panic("implement me")
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
// CreateCancellableContext creates a cancellable context
func (cm *simpleContextManager) CreateCancellableContext(parent context.Context) (context.Context, context.CancelFunc) {
// TODO: Implement cancellable context creation
// Hint: Use context.WithCancel(parent)
return context.WithCancel(parent)
panic("implement me")
}
// CreateCancellableContext creates a cancellable context
func (cm *simpleContextManager) CreateCancellableContext(parent context.Context) (context.Context, context.CancelFunc) {
// TODO: Implement cancellable context creation
// Hint: Use context.WithCancel(parent)
return context.WithCancel(parent)
}
🤖 Prompt for AI Agents
In `@challenge-30/submissions/MuraliMohan-2000/solution-template.go` around lines
38 - 45, Several methods (CreateCancellableContext, CreateTimeoutContext,
AddValue, GetValue, ExecuteWithContext, WaitForCompletion, SimulateWork, and
ProcessItems) contain unreachable panic("implement me") statements immediately
after return statements which causes Go compile errors; remove those trailing
panic calls so the function returns are the final statements (e.g., delete the
panic("implement me") line in CreateCancellableContext that follows the return
from context.WithCancel(parent)) and ensure no other methods in the file contain
return-followed-by-panic patterns.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant