parallel.waitForAll

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]

ExampleDownload 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
<nowiki>
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()
</nowiki>
Output Writes the contents of example.computercraft.cc to the filename that the user entered.

parallel.waitForAll
Function
Syntax
parallel.waitForAll(
  • functions... : function
)

Returns nil
API parallel
Source CC:Tweaked (source)

References

  1. "CC-Tweaked/parallel.lua". GitHub. 2017-06-12. Retrieved 2018-08-06.
This article is issued from Computercraft. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.