« Return to Thread: Returning JSON output from a handler thread still running?

Returning JSON output from a handler thread still running?

by Torbjörn Lager-2 :: Rate this Message:

Reply to Author | View in Thread

Hello,

Please have a look at the following code:

:- use_module(library('http/thread_httpd')).
:- use_module(library('http/http_dispatch')).
:- use_module(library('http/json')).
:- use_module(library('http/http_json')).

:- http_handler('/doit', doit, [spawn([alias(test)])]).

doit(_Requestl) :-
    reply_json(json([a=result])),
    thread_get_message(Event),
    process(Event).

:- http_server(http_dispatch, [port(5000)]).


The call to thread_get_message/1 blocks (as it should), which seems to
imply that no JSON is returned to the browser (until I kill the
server). Does it have to be that way (I don't see why)? Is there any
way I can send JSON to the client and still keep the thread on the
server running?

(What I'm trying to find here is a way to ask for one solution at the
time for a Prolog goal entered in a web interface. I have written code
that should have worked, had only the above worked... Maybe there are
other ideas for how to accomplish what I want to do? I've looked at
Uwe Lestas N-Queens demo, but it striked me as too complicated, and I
really would like to work against the SWI webserver...)

Thanks in advance!

Best regards,
Torbjörn

--
Torbjörn Lager
Professor of General and Computational Linguistics
Department of Philosophy, Linguistics and Theory of Science
Box 200, SE-405 30 Göteborg, Sweden
Phone: +46317864413
_______________________________________________
SWI-Prolog mailing list
SWI-Prolog@...
https://mailbox.iai.uni-bonn.de/mailman/listinfo.cgi/swi-prolog

 « Return to Thread: Returning JSON output from a handler thread still running?