Synchronous concurrency: Difference between revisions
Content added Content deleted
(→Using threads: Add a join, otherwise there is a race issue.) |
(→Using coroutines: Use forEachLine over useLines; No need to close the file.) |
||
Line 1,542: | Line 1,542: | ||
===Using coroutines=== |
===Using coroutines=== |
||
Uses experimental features and will change in the future. Same output as the threads version. |
Uses experimental features and will change in the future. Same output as the threads version. |
||
⚫ | |||
⚫ | |||
⚫ | |||
import kotlinx.coroutines.async |
import kotlinx.coroutines.async |
||
Line 1,562: | Line 1,561: | ||
} |
} |
||
File("input.txt").bufferedReader(). |
File("input.txt").bufferedReader().forEachLine { line -> lines.send(line) } |
||
for (line in text) { |
|||
lines.send(line) |
|||
} |
|||
} |
|||
lines.close() |
|||
println("\nNumber of lines printed = ${count.await()}") |
println("\nNumber of lines printed = ${count.await()}") |
||
} |
} |
||
⚫ | |||
} |
|||
</lang> |
|||
=={{header|Logtalk}}== |
=={{header|Logtalk}}== |