Two simultaneous routines

Asked

Viewed 58 times

4

How do I run two routines simultaneously in the same program? I’m trying to download a file, and print a value while downloading. Exactly that:

http = require "socket.http"
function downloadFile(url)
download = http.request(url)
return download
end
repeat
print("--")
until downloadFile("http://pokedg/patch/1.7z")

But just return:

--

And it ends.

1 answer

5


Lua does not allow preemptive multitasking, only coroutines, which are collaborative multitasking.

Unless the library of socket.http allows simultaneous downloads, the only solution is to run fully separated Lua states in separate threads. (Threads of the operating system, not Lua.)

  • How can I do that?

  • @Gabrielsales, you need to know how to create and run separate threads. Once done, create a Moon states in each of them and run Moon normally.

  • I found what you needed, thank you. http://www.lua.org/pil/9.4.html

  • @Gabrielsales, great! I had forgotten this... I suggest you add an answer explaining this.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.