Debian Codegraph @

doc/src/manual/cowboy_stream.init.asciidoc

raw
1 = cowboy_stream:init(3)
2
3 == Name
4
5 cowboy_stream:init - Initialize a stream
6
7 == Description
8
9 [source,erlang]
10 ----
11 init(StreamID, Req, Opts) -> {Commands, State}
12
13 StreamID :: cowboy_stream:stream_id()
14 Req :: cowboy_req:req()
15 Opts :: cowboy:opts()
16 Commands :: cowboy_stream:commands()
17 State - opaque
18 ----
19
20 Initialize a stream.
21
22 This function must be called by all stream handlers. It will
23 initialize the next configured stream handler.
24
25 == Arguments
26
27 StreamID::
28
29 The stream ID.
30
31 Req::
32
33 The Req object.
34
35 Opts::
36
37 The protocol options.
38
39 Commands::
40
41 The commands to be executed.
42
43 State::
44
45 The state for the next stream handler.
46
47 == Return value
48
49 A list of commands and an opaque state is returned.
50
51 The list of commands returned should be included in the
52 commands returned from the current stream handler. It
53 can be modified if necessary.
54
55 The state should be stored in the current stream
56 handler's state and passed to `cowboy_stream` when
57 necessary. The state should be treated as opaque.
58
59 == Changelog
60
61 * *2.0*: Function introduced.
62
63 == Examples
64
65 .Initialize the next stream handler
66 [source,erlang]
67 ----
68 init(StreamID, Req, Opts) ->
69 MyCommands = my_commands(),
70 {Commands, Next} = cowboy_stream:init(StreamID, Req, Opts),
71 {MyCommands ++ Commands, #state{next=Next}}.
72 ----
73
74 == See also
75
76 link:man:cowboy_stream(3)[cowboy_stream(3)],
77 link:man:cowboy_stream:data(3)[cowboy_stream:data(3)],
78 link:man:cowboy_stream:info(3)[cowboy_stream:info(3)],
79 link:man:cowboy_stream:terminate(3)[cowboy_stream:terminate(3)],
80 link:man:cowboy_stream:early_error(3)[cowboy_stream:early_error(3)]