1Dancer2::Core::ResponseU:s:eDrelCaoynetdr(i3b)uted PerlDDaonccuemre2n:t:aCtoiroen::Response::Delayed(3)
2
3
4
6 Dancer2::Core::Response::Delayed - Delayed responses
7
9 version 0.207000
10
12 my $response = Dancer2::Core::Response::Delayed->new(
13 request => Dancer2::Core::Request->new(...),
14 response => Dancer2::Core::Response->new(...),
15 cb => sub {...},
16
17 # optional error handling
18 error_cb => sub {
19 my ($error) = @_;
20 ...
21 },
22 );
23
24 # or in an app
25 get '/' => sub {
26 # delayed response:
27 delayed {
28 # streaming content
29 content "data";
30 content "more data";
31
32 # close user connection
33 done;
34 } on_error => sub {
35 my ($error) = @_;
36 warning 'Failed to stream to user: ' . request->remote_address;
37 };
38 };
39
41 This object represents a delayed (asynchronous) response for Dancer2.
42 It can be used via the "delayed" keyword.
43
44 It keeps references to a request and a response in order to avoid
45 keeping a reference to the application.
46
48 request
49 Contains a request the delayed response uses.
50
51 In the context of a web request, this will be the request that existed
52 when the delayed response has been created.
53
54 response
55 Contains a response the delayed response uses.
56
57 In the context of a web request, this will be the response that existed
58 when the delayed response has been created.
59
60 cb
61 The code that will be run asynchronously.
62
63 error_cb
64 A callback for handling errors. This callback receives the error as its
65 first (and currently only) parameter.
66
68 is_halted
69 A method indicating whether the response has halted.
70
71 This is useless in the context of an asynchronous request so it simply
72 returns no.
73
74 This method is likely going away.
75
76 has_passed
77 A method indicating whether the response asked to skip the current
78 response.
79
80 This is useless in the context of an asynchronous request so it simply
81 returns no.
82
83 This method is likely going away.
84
85 to_psgi
86 Create a PSGI response. The way it works is by returning a proper PSGI
87 response subroutine which localizes the request and response (in case
88 the callback wants to edit them without a reference to them), and then
89 calls the callback.
90
91 Finally, when the callback is done, it asks the response (whether it
92 was changed or not) to create its own PSGI response (calling "to_psgi")
93 and sends that to the callback it receives as a delayed response.
94
96 Dancer Core Developers
97
99 This software is copyright (c) 2018 by Alexis Sukrieh.
100
101 This is free software; you can redistribute it and/or modify it under
102 the same terms as the Perl 5 programming language system itself.
103
104
105
106perl v5.28.0 2018-11-14Dancer2::Core::Response::Delayed(3)