From a16b7e9c3abec3fa7414e79362587aa6af067731 Mon Sep 17 00:00:00 2001 From: shy Date: Tue, 5 Dec 2023 23:17:43 +0800 Subject: [PATCH] add sleep --- base/cli/mirrors.go | 4 +++- base/web/broad.go | 6 ++++-- base/web/dream.go | 5 ++--- base/web/route.go | 2 +- core/chat/grant.go | 4 ++-- core/code/vimer.go | 2 +- core/code/xterm.go | 2 +- exec.go | 7 +++++-- init.go | 5 ++--- misc/ssh/connect.go | 8 +++++--- misc/ssh/xterm.go | 4 ++-- misc/tmux/session.go | 7 +++---- misc/wx/ide.go | 2 +- 13 files changed, 32 insertions(+), 26 deletions(-) diff --git a/base/cli/mirrors.go b/base/cli/mirrors.go index de147cb6..b3a02d98 100644 --- a/base/cli/mirrors.go +++ b/base/cli/mirrors.go @@ -101,7 +101,9 @@ func insert(m *ice.Message, sys, cmd string, arg ...string) bool { return false } if len(arg) > 0 { - m.GoSleep("300ms", mdb.INSERT, kit.Keys(CLI, MIRRORS), "", mdb.ZONE, arg[0], OSID, sys, CMD, cmd+lex.SP+kit.Select(arg[0], arg, 1)) + m.GoSleep300ms(func() { + m.Cmd(mdb.INSERT, kit.Keys(CLI, MIRRORS), "", mdb.ZONE, arg[0], OSID, sys, CMD, cmd+lex.SP+kit.Select(arg[0], arg, 1)) + }) } return true } diff --git a/base/web/broad.go b/base/web/broad.go index 2704b24f..256be213 100644 --- a/base/web/broad.go +++ b/base/web/broad.go @@ -20,8 +20,10 @@ func _broad_send(m *ice.Message, to_host, to_port string, host, port string, arg }) } func _broad_serve(m *ice.Message) { - m.GoSleep("30ms", tcp.HOST, func(value ice.Maps) { - _broad_send(m, "", "", value[aaa.IP], m.Option(tcp.PORT), gdb.EVENT, tcp.LISTEN, mdb.NAME, ice.Info.NodeName, mdb.TYPE, ice.Info.NodeType) + m.GoSleep300ms(func() { + m.Cmd(tcp.HOST, func(value ice.Maps) { + _broad_send(m, "", "", value[aaa.IP], m.Option(tcp.PORT), gdb.EVENT, tcp.LISTEN, mdb.NAME, ice.Info.NodeName, mdb.TYPE, ice.Info.NodeType) + }) }) m.Cmd(tcp.SERVER, tcp.LISTEN, mdb.TYPE, tcp.UDP4, mdb.NAME, logs.FileLine(1), m.OptionSimple(tcp.HOST, tcp.PORT), func(from *net.UDPAddr, buf []byte) { msg := m.Spawn(buf).Logs(tcp.RECV, BROAD, string(buf), nfs.FROM, from) diff --git a/base/web/dream.go b/base/web/dream.go index 91f556af..34c29a20 100644 --- a/base/web/dream.go +++ b/base/web/dream.go @@ -139,8 +139,7 @@ func init() { DREAM: {Name: "dream name@key auto create repos startall stopall publish cmd cat", Help: "梦想家", Icon: "Launchpad.png", Actions: ice.MergeActions(ice.Actions{ ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) { m = m.Spawn() - m.Go(func() { - m.Sleep("10s") + m.GoSleep("10s", func() { mdb.HashSelects(m).Table(func(value ice.Maps) { if value[cli.RESTART] == "always" && nfs.Exists(m, path.Join(ice.USR_LOCAL_WORK+value[mdb.NAME])) { m.Cmd(DREAM, cli.START, kit.Dict(mdb.NAME, value[mdb.NAME])) @@ -254,7 +253,7 @@ func init() { }}, DREAM_CLOSE: {Hand: func(m *ice.Message, arg ...string) { if m.Option(cli.DAEMON) == ice.OPS && m.Cmdv(SPACE, m.Option(mdb.NAME), mdb.STATUS) != cli.STOP { - m.Go(func() { m.Sleep300ms(DREAM, cli.START, m.OptionSimple(mdb.NAME)) }) + m.GoSleep300ms(func() { m.Cmd(DREAM, cli.START, m.OptionSimple(mdb.NAME)) }) } }}, DREAM_TABLES: {Hand: func(m *ice.Message, arg ...string) { diff --git a/base/web/route.go b/base/web/route.go index 6d5d8795..86b7df5a 100644 --- a/base/web/route.go +++ b/base/web/route.go @@ -84,7 +84,7 @@ func init() { }}, cli.BUILD: {Name: "build space", Help: "构建", Hand: func(m *ice.Message, arg ...string) { _route_toast(m, m.Option(SPACE), m.PrefixKey(), "_build") - func() { defer ToastProcess(m)(); m.Sleep("3s") }() + func() { defer ToastProcess(m)(); m.Sleep3s() }() m.Cmdy("", "travel") }}, "_build": {Hand: func(m *ice.Message, arg ...string) { diff --git a/core/chat/grant.go b/core/chat/grant.go index d5be16ec..ea12d695 100644 --- a/core/chat/grant.go +++ b/core/chat/grant.go @@ -20,9 +20,9 @@ func init() { Index.MergeCommands(ice.Commands{ GRANT: {Name: "grant space auto", Help: "授权", Actions: ice.MergeActions(ice.Actions{ web.SPACE_LOGIN: {Hand: func(m *ice.Message, arg ...string) { - m.Go(func() { + m.GoSleep30ms(func() { link := tcp.PublishLocalhost(m, m.MergePodCmd("", "", web.SPACE, m.Option(mdb.NAME))) - m.Sleep30ms(web.SPACE, m.Option(mdb.NAME), cli.PWD, m.Option(mdb.NAME), link, m.Cmdx(cli.QRCODE, link)) + m.Cmd(web.SPACE, m.Option(mdb.NAME), cli.PWD, m.Option(mdb.NAME), link, m.Cmdx(cli.QRCODE, link)) }) }}, web.HOME: {Help: "首页", Hand: func(m *ice.Message, arg ...string) { m.ProcessOpen(web.MergeLink(m, web.CHAT_PORTAL)) }}, diff --git a/core/code/vimer.go b/core/code/vimer.go index eae2a9dd..6895f67b 100644 --- a/core/code/vimer.go +++ b/core/code/vimer.go @@ -179,7 +179,7 @@ func init() { cmds = []string{COMPILE, ice.SRC_WEBVIEW_GO, path.Join(app, _app)} } if msg := m.Cmd(cmds); cli.IsSuccess(msg) { - if m.Go(func() { m.Sleep30ms().Cmd(UPGRADE, cli.RESTART) }); isWebview() { + if m.GoSleep30ms(func() { m.Cmd(UPGRADE, cli.RESTART) }); isWebview() { m.Cmd(cli.DAEMON, "./bin/ice.bin", cli.FOREVER, cli.DELAY, "300ms", cli.SYSTEM, cli.OPEN, app) } } else { diff --git a/core/code/xterm.go b/core/code/xterm.go index 8a208e80..a497d3a6 100644 --- a/core/code/xterm.go +++ b/core/code/xterm.go @@ -41,7 +41,7 @@ func _xterm_get(m *ice.Message, h string) xterm.XTerm { for { if n, e := term.Read(buf); !m.Warn(e) && e == nil { if _xterm_echo(m, h, string(buf[:n])); len(text) > 0 { - kit.If(text[0], func(cmd string) { m.Go(func() { m.Sleep300ms(); term.Write([]byte(cmd + lex.NL)) }) }) + kit.If(text[0], func(cmd string) { m.GoSleep300ms(func() { term.Write([]byte(cmd + lex.NL)) }) }) text = text[1:] } } else { diff --git a/exec.go b/exec.go index e4c246d3..21226b2d 100644 --- a/exec.go +++ b/exec.go @@ -57,9 +57,12 @@ func (m *Message) Sleep(d Any, arg ...Any) *Message { func (m *Message) Sleep300ms(arg ...Any) *Message { return m.Sleep("300ms", arg...) } func (m *Message) Sleep30ms(arg ...Any) *Message { return m.Sleep("30ms", arg...) } func (m *Message) Sleep3s(arg ...Any) *Message { return m.Sleep("3s", arg...) } -func (m *Message) GoSleep(t string, arg ...Any) { - m.Go(func() { m.Spawn(kit.Dict(MSG_COUNT, "0")).Sleep(t).Cmd(arg...) }) +func (m *Message) GoSleep(t string, cb func(), arg ...Any) { + m.Go(func() { m.Spawn(kit.Dict(MSG_COUNT, "0")).Sleep(t); cb() }) } +func (m *Message) GoSleep300ms(cb func(), arg ...Any) { m.GoSleep("300ms", cb, arg...) } +func (m *Message) GoSleep30ms(cb func(), arg ...Any) { m.GoSleep("30ms", cb, arg...) } +func (m *Message) GoSleep3s(cb func(), arg ...Any) { m.GoSleep("3s", cb, arg...) } func (m *Message) Go(cb func(), arg ...Any) *Message { meta := m.FormatTaskMeta() meta.FileLine = kit.FileLine(2, 3) diff --git a/init.go b/init.go index 0f1f92d7..d07a933c 100644 --- a/init.go +++ b/init.go @@ -59,11 +59,10 @@ var Index = &Context{Name: ICE, Help: "冰山模块", Commands: Commands{ loadImportant(m) }}, QUIT: {Hand: func(m *Message, arg ...string) { - m.Go(func() { m.Sleep30ms(); os.Exit(kit.Int(kit.Select("0", arg, 0))) }) + m.GoSleep300ms(func() { os.Exit(kit.Int(kit.Select("0", arg, 0))) }) }}, EXIT: {Hand: func(m *Message, arg ...string) { - m.Go(func() { - m.Sleep30ms() + m.GoSleep300ms(func() { m.root.Option(EXIT, kit.Select("0", arg, 0)) m.Cmd(SOURCE, ETC_EXIT_SHY) m.Cmd(CTX_EXIT) diff --git a/misc/ssh/connect.go b/misc/ssh/connect.go index 392e755f..636fd5d4 100644 --- a/misc/ssh/connect.go +++ b/misc/ssh/connect.go @@ -91,7 +91,7 @@ func _ssh_dial(m *ice.Message, cb func(net.Conn), arg ...string) { } }, arg...) } -func _ssh_conn(m *ice.Message, cb func(*ssh.Client), arg ...string) { +func _ssh_conn(m *ice.Message, cb func(*ssh.Client), arg ...string) (err error) { methods := []ssh.AuthMethod{} methods = append(methods, ssh.PublicKeysCallback(func() ([]ssh.Signer, error) { key, err := ssh.ParsePrivateKey([]byte(m.Cmdx(nfs.CAT, kit.HomePath(m.OptionDefault(PRIVATE, ID_RSA_KEY))))) @@ -117,12 +117,14 @@ func _ssh_conn(m *ice.Message, cb func(*ssh.Client), arg ...string) { return })) m.Cmd(tcp.CLIENT, tcp.DIAL, mdb.TYPE, SSH, mdb.NAME, m.Option(tcp.HOST), m.OptionSimple(tcp.HOST, tcp.PORT), arg, func(c net.Conn) { - conn, chans, reqs, err := ssh.NewClientConn(c, m.Option(tcp.HOST)+nfs.DF+m.Option(tcp.PORT), &ssh.ClientConfig{ + conn, chans, reqs, _err := ssh.NewClientConn(c, m.Option(tcp.HOST)+nfs.DF+m.Option(tcp.PORT), &ssh.ClientConfig{ User: m.Option(aaa.USERNAME), Auth: methods, BannerCallback: func(message string) error { return nil }, HostKeyCallback: func(hostname string, remote net.Addr, key ssh.PublicKey) error { return nil }, }) - kit.If(!m.Warn(err), func() { cb(ssh.NewClient(conn, chans, reqs)) }) + kit.If(!m.Warn(_err), func() { cb(ssh.NewClient(conn, chans, reqs)) }) + err = _err }) + return } func _ssh_hold(m *ice.Message, c *ssh.Client) { if s, e := _ssh_session(m, c); !m.Warn(e, ice.ErrNotValid) { diff --git a/misc/ssh/xterm.go b/misc/ssh/xterm.go index 9467b57e..f5775eda 100644 --- a/misc/ssh/xterm.go +++ b/misc/ssh/xterm.go @@ -25,8 +25,8 @@ func (s XTerm) Close() error { return s.Session.Close() } -func Shell(m *ice.Message, cb func(xterm.XTerm)) { - _ssh_conn(m, func(c *ssh.Client) { +func Shell(m *ice.Message, cb func(xterm.XTerm)) error { + return _ssh_conn(m, func(c *ssh.Client) { if s, e := c.NewSession(); !m.Warn(e, ice.ErrNotValid) { defer s.Close() w, _ := s.StdinPipe() diff --git a/misc/tmux/session.go b/misc/tmux/session.go index 9e413591..0fe74fa8 100644 --- a/misc/tmux/session.go +++ b/misc/tmux/session.go @@ -107,8 +107,7 @@ func init() { if !cli.IsSuccess(_tmux_cmd(m, SPLIT_WINDOW, "-t", kit.Keys(name, "1"), "-p", "40")) { return } - m.Go(func() { - m.Sleep300ms() + m.GoSleep300ms(func() { _tmux_cmd(m, SEND_KEYS, "-t", kit.Keys(name, "2"), "ish_miss_log", ENTER) _tmux_cmd(m, SEND_KEYS, "-t", kit.Keys(name, "1"), "vi etc/miss.sh", ENTER) }) @@ -159,8 +158,8 @@ func init() { }).Sleep30ms() }}, web.DREAM_CREATE: {Hand: func(m *ice.Message, arg ...string) { - m.Go(func() { - nfs.Exists(m.Sleep3s(), path.Join(ice.USR_LOCAL_WORK, m.Option(mdb.NAME)), func(p string) { m.Cmd("", mdb.CREATE) }) + m.GoSleep3s(func() { + nfs.Exists(m, path.Join(ice.USR_LOCAL_WORK, m.Option(mdb.NAME)), func(p string) { m.Cmd("", mdb.CREATE) }) }) }}, }, Hand: func(m *ice.Message, arg ...string) { diff --git a/misc/wx/ide.go b/misc/wx/ide.go index 50bd8e65..8d125769 100644 --- a/misc/wx/ide.go +++ b/misc/wx/ide.go @@ -60,7 +60,7 @@ func init() { }}, aaa.LOGIN: {Help: "登录", Hand: func(m *ice.Message, arg ...string) { p := nfs.TempName(m) - m.Go(func() { web.PushNoticeGrow(m.Sleep("1s"), ice.Render(m, ice.RENDER_IMAGES, web.SHARE_LOCAL+p)) }) + m.GoSleep("1s", func() { web.PushNoticeGrow(m, ice.Render(m, ice.RENDER_IMAGES, web.SHARE_LOCAL+p)) }) IdeCli(m, "", _ide_args_cli(m), _ide_args_qrcode(m, p)).ProcessRefresh() }}, web.ADMIN: {Help: "后台", Hand: func(m *ice.Message, arg ...string) {