fubark / cyber

Fast and concurrent scripting.
https://cyberscript.dev
MIT License
1.16k stars 38 forks source link

Question about fetchUrl #49

Closed GabCores closed 1 year ago

GabCores commented 1 year ago

hi there !, In Linux and Windows fetchUrl works as an asynchronous function Is this the expected outcome? if so , all cyberscript functions are asynchronous ? I know you mention that asynchronous management is on the road , but what is the native nature of the language ? thanks!

fubark commented 1 year ago

fetchUrl is currently synchronous. If you're getting no response, then it's probably a bug with the builtin http client; you should post what url you're using if that's the case. You can also use os.execCmd if you have an installed http client like curl.

There will be an equivalent of await in the language, although the design hasn't been finalized. I don't think there would be a builtin async io library though. Instead, Cyber would provide the ability to create one by exposing an api for Promises.

GabCores commented 1 year ago

pls , try this sample

while true: resp = fetchUrl('http://httpstat.us/200?sleep=10000') print resp

no delay of 10s between calls what is wrong with this expectations ?

by the way , thanks for fixing sleep on Windows!

fubark commented 1 year ago

No problem!

This looks like the query parameter isn't sent. So it's actually doing this: GET /200 HTTP/1.1 instead of this GET /200?sleep=10000 HTTP/1.1 That's why you're getting a response so quickly. I'll make the fix now, one moment...

Edit: This should be working now

GabCores commented 1 year ago

now working fine!