Skip to content

Commit

Permalink
feat(context): close handle
Browse files Browse the repository at this point in the history
  • Loading branch information
solywsh committed Dec 8, 2022
1 parent 8f27910 commit 74479e0
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions chatgpt.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ type ChatGPT struct {
maxToken int
timeOut time.Duration
timeOutChan chan struct{}
cancel func()
}

func New(ApiKey, UserId string, timeOut time.Duration) *ChatGPT {
Expand All @@ -21,7 +22,6 @@ func New(ApiKey, UserId string, timeOut time.Duration) *ChatGPT {
go func() {
<-ctx.Done()
timeOutChan <- struct{}{}
cancel()
}()
return &ChatGPT{
client: gogpt.NewClient(ApiKey),
Expand All @@ -30,10 +30,13 @@ func New(ApiKey, UserId string, timeOut time.Duration) *ChatGPT {
maxToken: 1024,
timeOut: timeOut,
timeOutChan: timeOutChan,
cancel: func() {
cancel()
},
}
}
func (c *ChatGPT) Close() {
c.ctx.Done()
c.cancel()
}

func (c *ChatGPT) GetTimeOutChan() chan struct{} {
Expand Down

0 comments on commit 74479e0

Please sign in to comment.