Skip to content

Commit

Permalink
Added ability to use custom context
Browse files Browse the repository at this point in the history
  • Loading branch information
KoNekoD committed Oct 18, 2023
1 parent 01ca320 commit 07c0302
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,8 @@ type ClientOpts struct {
// Custom middlewares
Middlewares []telegram.Middleware
// Custom context(if you need to stop the client from running externally)
Ctx func() (ctx context.Context, cancel context.CancelFunc)
Ctx context.Context
CtxCancel context.CancelFunc
}

// NewClient creates a new gotgproto client and logs in to telegram.
Expand All @@ -127,8 +128,8 @@ func NewClient(appId int, apiHash string, cType ClientType, opts *ClientOpts) (*
}

ctx, cancel := context.WithCancel(context.Background())
if opts.Ctx != nil {
ctx, cancel = opts.Ctx()
if opts.Ctx != nil && opts.CtxCancel != nil {
ctx, cancel = opts.Ctx, opts.CtxCancel
}

var sessionStorage telegram.SessionStorage
Expand Down

0 comments on commit 07c0302

Please sign in to comment.