Skip to content

Instantly share code, notes, and snippets.

@hymkor
Created April 8, 2024 10:38
Show Gist options
  • Save hymkor/7e1f7ddd2692fbc365e96fab50e5525d to your computer and use it in GitHub Desktop.
Save hymkor/7e1f7ddd2692fbc365e96fab50e5525d to your computer and use it in GitHub Desktop.
background worker while key-in
func until(cond func(), work func() bool) {
endSig := make(chan struct{})
go func() {
for {
select {
case <-endSig:
return
default:
if !work() {
<-endSig
return
}
}
}
}()
cond()
endSig <- struct{}{}
close(endSig)
}
func mains() error {
// :
var ch string
until(func() { ch, err = readline.GetKey(tty1) }, func() bool {
if reader == nil {
return false
}
row, err := uncsv.ReadLine(reader, mode)
if err != nil {
reader = nil
if err != io.EOF {
return false
}
}
csvlines.PushBack(row)
return err != io.EOF
})
if err != nil {
return err
}
// :
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment