|
@@ -151,11 +151,14 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|
|
|
|
|
|
|
case tickMsg:
|
|
case tickMsg:
|
|
|
cmds = append(cmds, m.Tick())
|
|
cmds = append(cmds, m.Tick())
|
|
|
- cmds = append(cmds, m.Poll)
|
|
|
|
|
|
|
+ cmds = append(cmds, m.Poll())
|
|
|
|
|
+
|
|
|
|
|
+ case pollResultMsg:
|
|
|
|
|
+ m.Addresses[msg.index].results = msg.results
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- m.viewport, cmd = m.viewport.Update(msg)
|
|
|
|
|
m.viewport.SetContent(m.content())
|
|
m.viewport.SetContent(m.content())
|
|
|
|
|
+ m.viewport, cmd = m.viewport.Update(msg)
|
|
|
cmds = append(cmds, cmd)
|
|
cmds = append(cmds, cmd)
|
|
|
// cmds = append(cmds, m.Poll)
|
|
// cmds = append(cmds, m.Poll)
|
|
|
|
|
|
|
@@ -180,15 +183,15 @@ func (m Model) View() string {
|
|
|
return fmt.Sprintf("\n%s\n%s\n%s", header, m.viewport.View(), footer)
|
|
return fmt.Sprintf("\n%s\n%s\n%s", header, m.viewport.View(), footer)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-// A wrapper for the underlying [tui.Address.Poll] function. For each address in
|
|
|
|
|
-// [tui.Model.Addresses], run its respective Poll function and update [tui.Model]
|
|
|
|
|
-//
|
|
|
|
|
-// NOTE(async): this function fully blocks execution of the current thread.
|
|
|
|
|
-func (m Model) Poll() tea.Msg {
|
|
|
|
|
|
|
+// Returns a batched set of tea.Cmd functions for each address.
|
|
|
|
|
+func (m Model) Poll() tea.Cmd {
|
|
|
|
|
+ var cmds []tea.Cmd
|
|
|
|
|
+
|
|
|
for i, element := range m.Addresses {
|
|
for i, element := range m.Addresses {
|
|
|
- element.Poll()
|
|
|
|
|
- // element.results = append(element.results, -1)
|
|
|
|
|
- m.Addresses[i] = element
|
|
|
|
|
|
|
+ cmds = append(cmds, func() tea.Msg {
|
|
|
|
|
+ results, err := element.Poll()
|
|
|
|
|
+ return pollResultMsg{results: results, err: err, index: i}
|
|
|
|
|
+ })
|
|
|
}
|
|
}
|
|
|
- return nil
|
|
|
|
|
|
|
+ return tea.Batch(cmds...)
|
|
|
}
|
|
}
|