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.SetFocus(dlg.dateCtl)
win.ShowWindow(dlg.wnd, win.SW_NORMAL) win.ShowWindow(dlg.wnd, win.SW_NORMAL)
if opts.ctx != nil { if opts.ctx != nil && opts.ctx.Done() != nil {
wait := make(chan struct{}) wait := make(chan struct{})
defer close(wait) defer close(wait)
go func() { 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.ShowWindow(dlg.wnd, win.SW_NORMAL)
win.SendMessage(dlg.editCtl, win.EM_SETSEL, 0, intptr(-1)) 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{}) wait := make(chan struct{})
defer close(wait) defer close(wait)
go func() { go func() {

View file

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

View file

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

View file

@ -190,7 +190,7 @@ func (dlg *progressDialog) setup(opts options) error {
} }
once.Do(dlg.init.Done) once.Do(dlg.init.Done)
if opts.ctx != nil { if opts.ctx != nil && opts.ctx.Done() != nil {
wait := make(chan struct{}) wait := make(chan struct{})
defer close(wait) defer close(wait)
go func() { 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.ShowWindow(dlg.wnd, win.SW_NORMAL)
win.SendMessage(dlg.uEditCtl, win.EM_SETSEL, 0, intptr(-1)) 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{}) wait := make(chan struct{})
defer close(wait) defer close(wait)
go func() { go func() {

View file

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