3

Possible Duplicate:
Lua socket asynchronous calls

I think my question is pretty clear. So, how?

Community
  • 1
  • 1
Luaox
  • 167
  • 1
  • 3
  • 13
  • I can't seem to find the answer, post link please? – Luaox Jan 18 '13 at 15:25
  • Problem is: Those answers answers a different question: Namely how to send raw socket data asynchrounously. Now how to perform an asynch http request with the luasocket http api – TheMadsen Nov 01 '18 at 10:39

1 Answers1

6

Discussed in Programming in Lua (non-preemptive multithreading) and on SO here and here.

Community
  • 1
  • 1
Paul Kulchenko
  • 25,884
  • 3
  • 38
  • 56
  • Yes, that will work, but then you need to roll your own FTP hTTP etc on top of the bare sockets. The LTN stuff does not provide for asynchronous operation; It is simply a fancy callback mechanism during synchronous operation of the protocol engine. – TheMadsen Nov 01 '18 at 08:06
  • Answering myself after inspecting ltn12.lua: http.request can probably be wrapped in a coroutine with handling of IO based on lua-ev callbacks and a custom ltn12 sink (key givaway: It can probably be avoided to yield across C barriers). Maybe something for a rainy day. Any outcome shall be posted on this channel .. – TheMadsen Nov 01 '18 at 09:11
  • You don't need to roll your own; [copas](https://github.com/keplerproject/copas) provides async http handling (check examples in the `tests/` folder). – Paul Kulchenko Nov 01 '18 at 22:18
  • thanks for the pointer – TheMadsen Nov 02 '18 at 19:37