Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possible bug... or just needs documentation? #16

Open
torbjornlager opened this issue Aug 19, 2014 · 0 comments
Open

Possible bug... or just needs documentation? #16

torbjornlager opened this issue Aug 19, 2014 · 0 comments

Comments

@torbjornlager
Copy link
Contributor

Here, test1/0 and test2/0 should ideally behave in exactly the same way, but do not:

:- use_module(library(pengines)).

test1 :-
    pengine_create([
        src_text("
            run :-
               sleep(5),
               pengine_output(ping).
        ")]),
    pengine_event_loop(handler1, []).


handler1(create(ID, Data)) :- !,
    writeln(create(ID, Data)),
    pengine_ask(ID, run, []).
handler1(Event) :-
    writeln(Event).


test2 :-
    pengine_create([
        ask(run), % Note the ask option!
        src_text("
            run :-
               sleep(5),
               pengine_output(ping).
        ")]),
    pengine_event_loop(handler2, []).


handler2(Event) :-
    writeln(Event).


?- test1.
% After 0 seconds
create(d70f3973-87e0-448c-9080-4580a02b8508,[slave_limit(3)])
% After 5 seconds
output(d70f3973-87e0-448c-9080-4580a02b8508,ping)
success(d70f3973-87e0-448c-9080-4580a02b8508,[run],false)
destroy(d70f3973-87e0-448c-9080-4580a02b8508)
true.

?- test2.
% After 5 seconds
create(384e4387-22a8-471a-915c-3ceace71b5f8,[slave_limit(3)])
output(384e4387-22a8-471a-915c-3ceace71b5f8,ping)
success(384e4387-22a8-471a-915c-3ceace71b5f8,[run],false)
destroy(384e4387-22a8-471a-915c-3ceace71b5f8)
true.

?- 

The problem is that the pengine in test2/0 is waiting to wrap the first answer in the create event, but the first answer doesn't come until after 5 seconds. Now, suppose we had a blocking call instead of sleep/1 - that wouldn't work at all! (Fortunately, pengine_input/2 isn't blocking in a harmful way since it first prompts and it is the prompt that gets wrapped.)

Is this even fixable? If not, the fact that the use of the ask option and the use of pengine_ask/3 aren't always equivalent should perhaps be documented.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant