parallel.waitForAll

From ComputerCraft
Jump to: navigation, search

parallel.waitForAll
Function
Syntax
parallel.waitForAll()
Returns nil
API parallel
Source CC:Tweaked (source)

Switches between execution of the functions, until all of them are finished. If any of the functions errors, the message is propagated upwards from the parallel.waitForAll call.[1]

ExampleExampleDownload a file while reading the file name
The file download and read for the file name will execute in parallel, taking turns until both return. Since both read and http.get yield regularly (the first one waiting for characters, and the second waiting for a response), no deadlocking occurs.
Code
local handle, file
parallel.waitForAll(
  function()
    io.write("enter a file name: ")
    file = fs.open(read(), "w")
  end,
  function() handle = http.get("https://example.computercraft.cc") end
)
file.writeLine(handle.readAll())
handle.close()
file.close()
Output Writes the contents of example.computercraft.cc to the filename that the user entered.

References

  1. "CC-Tweaked/parallel.lua". GitHub. 2017-06-12. Retrieved 2018-08-06.