Optimize contexts that never cancel.

This commit is contained in:
Nuno Cruces 2024-02-23 13:07:06 +00:00
parent 99f1a258bc
commit 649da2441d
7 changed files with 7 additions and 7 deletions

View File

@ -102,7 +102,7 @@ func (dlg *calendarDialog) setup(text string, opts options) (time.Time, error) {
win.SetFocus(dlg.dateCtl)
win.ShowWindow(dlg.wnd, win.SW_NORMAL)
if opts.ctx != nil {
if opts.ctx != nil && opts.ctx.Done() != nil {
wait := make(chan struct{})
defer close(wait)
go func() {

View File

@ -97,7 +97,7 @@ func (dlg *entryDialog) setup(text string, opts options) (string, error) {
win.ShowWindow(dlg.wnd, win.SW_NORMAL)
win.SendMessage(dlg.editCtl, win.EM_SETSEL, 0, intptr(-1))
if opts.ctx != nil {
if opts.ctx != nil && opts.ctx.Done() != nil {
wait := make(chan struct{})
defer close(wait)
go func() {

View File

@ -128,7 +128,7 @@ func (dlg *listDialog) setup(text string, opts options) ([]string, error) {
win.SetFocus(dlg.listCtl)
win.ShowWindow(dlg.wnd, win.SW_NORMAL)
if opts.ctx != nil {
if opts.ctx != nil && opts.ctx.Done() != nil {
wait := make(chan struct{})
defer close(wait)
go func() {

View File

@ -121,7 +121,7 @@ func shellNotify(text string, opts options) error {
major, minor, _ := win.RtlGetNtVersionNumbers()
// On Windows 7 (6.1) and lower, wait up to 10 seconds to clean up.
if major < 6 || major == 6 && minor < 2 {
if opts.ctx != nil {
if opts.ctx != nil && opts.ctx.Done() != nil {
select {
case <-opts.ctx.Done():
case <-time.After(10 * time.Second):

View File

@ -190,7 +190,7 @@ func (dlg *progressDialog) setup(opts options) error {
}
once.Do(dlg.init.Done)
if opts.ctx != nil {
if opts.ctx != nil && opts.ctx.Done() != nil {
wait := make(chan struct{})
defer close(wait)
go func() {

View File

@ -113,7 +113,7 @@ func (dlg *passwordDialog) setup(opts options) (string, string, error) {
win.ShowWindow(dlg.wnd, win.SW_NORMAL)
win.SendMessage(dlg.uEditCtl, win.EM_SETSEL, 0, intptr(-1))
if opts.ctx != nil {
if opts.ctx != nil && opts.ctx.Done() != nil {
wait := make(chan struct{})
defer close(wait)
go func() {

View File

@ -118,7 +118,7 @@ func newDialogHook(ctx context.Context, icon any, title *string, init func(wnd w
title: title,
init: init,
}
if ctx != nil {
if ctx != nil && ctx.Done() != nil {
hook.done = make(chan struct{})
go hook.wait()
}