Closed otgo closed 5 years ago
local inpt = io.stdin:read()
This is blocking. You'll need to wrap it in a cqueues-yielding read operation. The easiest way to do so is:
local cs = require "cqueues.socket"
local stdin = cs.fdopen(0)
--- setup code here
local inpt = stdin:read()
--- etc.
but if, in my code im not using stdin? It is only an example
Example:
local cqueues = require 'cqueues'
local proc_functions = cqueues.new()
local proc_check = cqueues.new()
local function proc1()
while true do
proc_functions:loop()
end
end
local function proc2()
while true do
https = require 'ssl.https'
https.request("nnnn")
print("HELLO")
end)
-- proc_functions:loop() -- if I uncomment this, it works
end
end
proc_check:wrap(proc1)
proc_check:wrap(proc2)
proc_check:loop()
https.request("nnnn")
That is also a blocking operation. See lua-http
instead.
so, how could I do it with a ssl request?
lua-http is a library that integrates properly with cqueues and allows for it to perform operations without blocking up your client. You can change your example to, instead of using require 'ssl.https'
, instead require 'http.request
as provided by the library I mentioned. Examples on how to use an HTTP client with that library should exist on that link.
In addition to that, you're not checking errors returned from the proc_functions
loop, so you should wrap the loop function call in an assert()
or use some other method to handle the error.
okaay :3 thanks for it, i will answer there to make my request sucessfully
I've replicated that i want to do:
local cqueues = require 'cqueues'
local cop2 = cqueues.new()
local thread = cqueues.new()
thread:wrap(function() print("PRINT TESTING") end)
cop2:wrap(function()
while true do
assert(thread:step())
end
end)
cop2:wrap(function()
while true do
--_some_function_()
end
end)
assert(cop2:loop())
This is a flowchart:
Do you still have an open question here? I'm not sure I see a question any more...
ahmm...
I mean, i want to do something like that
Im trying to do a async process, this is my testing script:
Problem here is, i want to check if there are new functions, and execute it in "proc1"
How do I do that?