by fauigerzigerk · 15y ago · 0 comments
log(write(process(read(source))))
becomes: read(source, function(input) {
write(process(input), function(success) {
log(success)
})
})And of course thread based code can do other things as well during blocking IO - on other threads.
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
} 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.channels rule :)