luv icon indicating copy to clipboard operation
luv copied to clipboard

Problems in the repl

Open bentxt opened this issue 3 years ago • 1 comments

Hi, Sorry for the lack of a better title, and even worse the title is eventually wrong.

But the thing I want to accomplish is to interactively play with some functions in the repl. In stead of real data, all results look pretty abstract, maybe because Luv.Loop didn't kicked of all the events?

Here's my naive attempt.

let res = Luv.DNS.getaddrinfo ~family:`INET ~node:"google.com" ();;
Luv.Loop.run ();;

bentxt avatar Mar 25 '21 10:03 bentxt

Luv.DNS.getaddrinfo ~family:`INET ~node:"google.com" () returns a function that's waiting for you to give it a callback. Only once it gets your callback, will it actually start working on the query. The REPL should have told you that the type here is a function.

This example from the docs show how to pass a callback as the last argument to Luv.DNS.getaddrinfo. Once your callback gets called, you have to do some work to extract the actual result, also shown in the example.

There's also an issue about implementing a synchronous DNS API (#30), which would make all of this a bit less complicated.

aantron avatar Mar 25 '21 13:03 aantron