From 07c03023ba408691726f92d804e4ffae186a722a Mon Sep 17 00:00:00 2001 From: KoNekoD Date: Thu, 19 Oct 2023 02:45:49 +0400 Subject: [PATCH] Added ability to use custom context --- client.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/client.go b/client.go index 83cf434..04214e9 100644 --- a/client.go +++ b/client.go @@ -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. @@ -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