HI All,

So I've solved the issue with sessions and it appears as though it is mucking up the delayed subroutine and I've written a test case based on the example in the docs and I'm surely missing something as it doesn't work properly, since it blocks.

Here is a simple case of delayed blocking, I've moved the session code outside the subroutine which now does return.

get '/Load/:ID' => sub {
    my $ID = params->{'ID'};
    my $Username = "Test";
    session 'Username' => $Username;
    delayed {
      my $TextToWrite = ReturnText();
      sleep(10); # Do something that takes a few seconds
      content "$TextToWrite";
      done;
   };
};

at the "sleep" function, the application basically stops, waiting for sleep to complete.

The docs confused me as well, it says:

        content 'Hello, again!';
 
        # when done, close the connection
        done;
 
        # do whatever you want else, asynchronously
        # the user socket closed by now
        ...
    };
};

At the end it talks about doing stuff asynchronously, implying that
whatever was done previously was not asynchronous?

So yeah, some clarification would be awesome, or just someone with an example which works.


David






On Tue, Nov 17, 2015 at 1:56 PM, David H <untg99@gmail.com> wrote:
Thanks,
I've changed the custom headers.
There is something which is causing a "400 Bad Response".

I've narrowed it down to this simple use case:
get '/Load/:ID' => sub {
    my $ID = params->{'ID'};
   delayed {
      my $TextToWrite = ReturnText(); # Just returns "hi", works fine.
      my $Username = "Test";
      session 'Username' => $Username;   # Causes the whole thing to to return "400 Bad Response" and not work at all.
      header 'Content-Type' => "text/html; charset=UTF-8";
      flush;
      content "$TextToWrite";
      done;


   };
};

Notice the "session 'Username' => $Username."

That causes a "400 Bad Response" error. I'm guessing something to do with the session being set and returning before other stuff has happened??

Thanks,

David



On Tue, Nov 17, 2015 at 11:43 AM, Warren Young <wyml@etr-usa.com> wrote:
On Nov 16, 2015, at 6:09 PM, David H <untg99@gmail.com> wrote:
>
>     add_header 'X-Foo' => 'Bar’;

That’s probably an old DSL keyword.  It looks like it was replaced with ‘header’:

 https://metacpan.org/pod/distribution/Dancer2/lib/Dancer2/Manual.pod#header

Anyway, do you really need to set custom HTTP headers here?  It’s just an example.  If your app doesn’t need that, remove the line entirely.
_______________________________________________
dancer-users mailing list
dancer-users@dancer.pm
http://lists.preshweb.co.uk/mailman/listinfo/dancer-users