Skip to content

Commit

Permalink
ctx updated
Browse files Browse the repository at this point in the history
  • Loading branch information
yahya077 authored and yahya.hindioglu committed Mar 14, 2024
1 parent 89646e8 commit 996cca9
Showing 1 changed file with 2 additions and 7 deletions.
9 changes: 2 additions & 7 deletions context.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ type Context struct {
}

type IContextBuilder interface {
Timeout() time.Duration
Build() Context
}

Expand All @@ -20,25 +19,21 @@ type ContextBuilder struct {
}

func (b ContextBuilder) Build() Context {
if b.Timeout() == 0 {
if b.timeout == 0 {
return Context{
Ctx: context.Background(),
Cancel: nil,
}
}

ctx, cancel := context.WithTimeout(context.Background(), b.Timeout())
ctx, cancel := context.WithTimeout(context.Background(), b.timeout)

return Context{
Ctx: ctx,
Cancel: cancel,
}
}

func (b ContextBuilder) Timeout() time.Duration {
return b.timeout
}

func NewContextBuilder(timeout time.Duration) ContextBuilder {
return ContextBuilder{timeout}
}

0 comments on commit 996cca9

Please sign in to comment.