4 ms·
use channels, you can make them block so the first loop will wait for logger to finish the logging if you like do { source = <- sources // read a s
by dramaticus3 15y ago
use channels, you can make them block so the first loop will wait for logger to finish the logging if you like
do {
source = <- sources // read a source from the sources channel
if source
data = read(source)
process <- data // send it to the process channel
else
process <- nil
} while source
fn processor {
do {
data = <- process
result = process(data)
results <- result
} while data
}
fn writer {
do {
data = <- results
msg = write(data)
log <- msg
} while data
}
fn logger {
do {
msg = <- log
if msg
print msg
} while msg
}
- fauigerzigerk 15y agoMy ideal version would be something like parallel for(item in source) log(write(process(read(item)))) And let the compiler/runtime figure out how to do that. It could generate something similar to your code for instance.
- dramaticus3 15y agook, but now I have a generic logger that I can send all kind of messages to. I can use the source channel anywhere and pop a new data source into it etc. etc. channels rule :)