Skip to content

Commit

Permalink
Merge pull request #38 from foomo/feature/ownbrew-timeout
Browse files Browse the repository at this point in the history
feat: make timeout configurable
  • Loading branch information
franklinkim authored Aug 18, 2023
2 parents 33bf367 + 9df8614 commit 1b65437
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion integration/ownbrew/ownbrew.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ type (
tempDir string
cellarDir string
packages []Package
timeout time.Duration
}
Option func(*Ownbrew) error
)
Expand Down Expand Up @@ -77,6 +78,13 @@ func WithCellarDir(v string) Option {
}
}

func WithTimeout(v time.Duration) Option {
return func(o *Ownbrew) error {
o.timeout = v
return nil
}
}

// ------------------------------------------------------------------------------------------------
// ~ Constructor
// ------------------------------------------------------------------------------------------------
Expand All @@ -88,6 +96,7 @@ func New(l log.Logger, opts ...Option) (*Ownbrew, error) {
tempDir: ".posh/tmp",
tapDir: ".posh/ownbrew",
cellarDir: ".posh/bin",
timeout: 3 * time.Minute,
}
for _, opt := range opts {
if opt != nil {
Expand Down Expand Up @@ -251,7 +260,7 @@ func (o *Ownbrew) installRemote(ctx context.Context, pkg Package) error {
o.l.Info("installing remote:", pkg.String())
o.l.Debug("url:", url)

ctx, cancel := context.WithTimeout(ctx, 30*time.Second)
ctx, cancel := context.WithTimeout(ctx, o.timeout)
defer cancel()

req, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil)
Expand Down

0 comments on commit 1b65437

Please sign in to comment.