Created
April 8, 2024 10:38
-
-
Save hymkor/7e1f7ddd2692fbc365e96fab50e5525d to your computer and use it in GitHub Desktop.
background worker while key-in
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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