Skip to content

Commit 56b649f

Browse files
committed
Docs
1 parent 99c5e52 commit 56b649f

File tree

4 files changed

+109
-25
lines changed

4 files changed

+109
-25
lines changed

src/Node/HTTP2.purs

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -94,25 +94,25 @@
9494
-- | but we want to wait until they’ve all completed before we continue.
9595
-- |
9696
-- | ```
97-
-- | parSequence_
98-
-- | [ operation1
99-
-- | , operation2
100-
-- | , operation3
101-
-- | ]
97+
-- | parSequence_
98+
-- | [ operation1
99+
-- | , operation2
100+
-- | , operation3
101+
-- | ]
102102
-- | ```
103103
-- |
104104
-- | We can also use do-blocks in this idiom. And collect the results
105105
-- | if the results are all some interesting type instead of `Unit`.
106106
-- |
107107
-- | ```
108-
-- | [result1, result2, result3] <- parSequence
109-
-- | [ do
110-
-- | operation1
111-
-- | , do
112-
-- | operation2
113-
-- | , do
114-
-- | operation3
115-
-- | ]
108+
-- | [result1, result2, result3] <- parSequence
109+
-- | [ do
110+
-- | operation1
111+
-- | , do
112+
-- | operation2
113+
-- | , do
114+
-- | operation3
115+
-- | ]
116116
-- | ```
117117
-- |
118118
-- | #### Aff Idiom: Concurrent effects with heterogeneous return values
@@ -137,6 +137,20 @@
137137
-- | operation3
138138
-- | ```
139139
-- |
140+
-- | #### Aff Idiom: Surprising events
141+
-- |
142+
-- | We have `event1`, `event2`, and `event3`, which are
143+
-- | all side-effecting `Aff Unit` operations. We know one of them
144+
-- | will complete next, but we don’t know which one. We want to wait for
145+
-- | all of them at the same time.
146+
-- |
147+
-- | ```
148+
-- | parOneOf
149+
-- | [ event1
150+
-- | , event2
151+
-- | , event3
152+
-- | ]
153+
-- | ```
140154
module Node.HTTP2
141155
( HeadersObject(..)
142156
, toHeaders

src/Node/HTTP2/Client.purs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,28 +89,55 @@ close :: ClientHttp2Session -> Effect Unit -> Effect Unit
8989
close = unsafeCoerce Internal.close
9090

9191
-- | https://nodejs.org/docs/latest/api/http2.html#event-response
92+
-- |
93+
-- | Listen for one event, then remove the event listener.
94+
-- |
95+
-- | Returns an effect for removing the event listener before the event
96+
-- | is raised.
9297
foreign import onceResponse :: ClientHttp2Stream -> (HeadersObject -> Flags -> Effect Unit) -> Effect (Effect Unit)
9398

9499
-- | https://nodejs.org/docs/latest/api/http2.html#event-headers
100+
-- |
101+
-- | Listen for one event, then remove the event listener.
102+
-- |
103+
-- | Returns an effect for removing the event listener before the event
104+
-- | is raised.
95105
foreign import onceHeaders :: ClientHttp2Stream -> (HeadersObject -> Flags -> Effect Unit) -> Effect (Effect Unit)
96106

97107
-- | https://nodejs.org/docs/latest/api/http2.html#event-stream
98108
-- |
99109
-- | https://nodejs.org/docs/latest/api/http2.html#push-streams-on-the-client
110+
-- |
111+
-- | Listen for one event, then remove the event listener.
112+
-- |
113+
-- | Returns an effect for removing the event listener before the event
114+
-- | is raised.
100115
onceStream :: ClientHttp2Session -> (ClientHttp2Stream -> HeadersObject -> Flags -> Effect Unit) -> Effect (Effect Unit)
101116
onceStream = unsafeCoerce Internal.onceStream
102117

103118
-- | https://nodejs.org/docs/latest/api/http2.html#event-stream
104119
-- |
105120
-- | https://nodejs.org/docs/latest/api/http2.html#push-streams-on-the-client
121+
-- |
122+
-- | Returns an effect for removing the event listener.
106123
onStream :: ClientHttp2Session -> (ClientHttp2Stream -> HeadersObject -> Flags -> Effect Unit) -> Effect (Effect Unit)
107124
onStream = unsafeCoerce Internal.onStream
108125

109126
-- | https://nodejs.org/docs/latest/api/http2.html#event-error
127+
-- |
128+
-- | Listen for one event, then remove the event listener.
129+
-- |
130+
-- | Returns an effect for removing the event listener before the event
131+
-- | is raised.
110132
onceErrorSession :: ClientHttp2Session -> (Error -> Effect Unit) -> Effect (Effect Unit)
111133
onceErrorSession = unsafeCoerce Internal.onceEmitterError
112134

113135
-- | https://nodejs.org/docs/latest/api/http2.html#event-error_1
136+
-- |
137+
-- | Listen for one event, then remove the event listener.
138+
-- |
139+
-- | Returns an effect for removing the event listener before the event
140+
-- | is raised.
114141
onceErrorStream :: ClientHttp2Stream -> (Error -> Effect Unit) -> Effect (Effect Unit)
115142
onceErrorStream = unsafeCoerce Internal.onceError
116143

@@ -120,14 +147,26 @@ onceErrorStream = unsafeCoerce Internal.onceError
120147
foreign import oncePush :: ClientHttp2Stream -> (HeadersObject -> Flags -> Effect Unit) -> Effect (Effect Unit)
121148

122149
-- | https://nodejs.org/docs/latest/api/http2.html#event-trailers
150+
-- |
151+
-- | Listen for one event, then remove the event listener.
152+
-- |
153+
-- | Returns an effect for removing the event listener before the event
154+
-- | is raised.
123155
onceTrailers :: ClientHttp2Stream -> (HeadersObject -> Flags -> Effect Unit) -> Effect (Effect Unit)
124156
onceTrailers = unsafeCoerce Internal.onceTrailers
125157

126158
-- | https://nodejs.org/docs/latest/api/stream.html#event-data
159+
-- |
160+
-- | Returns an effect for removing the event listener.
127161
onData :: ClientHttp2Stream -> (Buffer -> Effect Unit) -> Effect (Effect Unit)
128162
onData = unsafeCoerce Internal.onData
129163

130164
-- | https://nodejs.org/docs/latest/api/net.html#event-end
165+
-- |
166+
-- | Listen for one event, then remove the event listener.
167+
-- |
168+
-- | Returns an effect for removing the event listener before the event
169+
-- | is raised.
131170
onceEnd :: ClientHttp2Stream -> Effect Unit -> Effect (Effect Unit)
132171
onceEnd = unsafeCoerce Internal.onceEnd
133172

src/Node/HTTP2/Server.Aff.purs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,6 @@ import Web.Fetch.AbortController as Web.Fetch.AbortController
6060
-- |
6161
-- | The argument is the `createServer` options.
6262
-- | See [`http2.createServer([options][, onRequestHandler])`](https://nodejs.org/docs/latest/api/http2.html#http2createserveroptions-onrequesthandler)
63-
-- |
64-
-- | Example:
65-
-- |
66-
-- | ```
67-
-- | server <- createServer $ unsafeToForeign
68-
-- | {
69-
-- | }
70-
-- | ```
7163
createServer
7264
:: OptionsObject
7365
-> Aff Http2Server
@@ -136,6 +128,11 @@ listen server options handler = makeAff \complete -> do
136128
Web.Fetch.AbortController.abort abortcontroller
137129

138130
-- | Create a secure (HTTPS) HTTP/2 server.
131+
-- |
132+
-- | The argument is the `createServer` options.
133+
-- | See [`http2.createServer([options][, onRequestHandler])`](https://nodejs.org/docs/latest/api/http2.html#http2createserveroptions-onrequesthandler)
134+
-- |
135+
-- | Required options: `key :: String`, `cert :: String`.
139136
createSecureServer
140137
:: OptionsObject
141138
-> Aff Http2SecureServer

src/Node/HTTP2/Server.purs

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,11 @@ closeServer :: Http2Server -> Effect Unit -> Effect Unit
8484
closeServer = unsafeCoerce Internal.close
8585

8686
-- | https://nodejs.org/docs/latest/api/net.html#event-close
87+
-- |
88+
-- | Listen for one event, then remove the event listener.
89+
-- |
90+
-- | Returns an effect for removing the event listener before the event
91+
-- | is raised.
8792
onceCloseServer :: Http2Server -> Effect Unit -> Effect (Effect Unit)
8893
onceCloseServer = unsafeCoerce Internal.onceServerClose
8994

@@ -106,24 +111,27 @@ closeServerSecure :: Http2SecureServer -> Effect Unit -> Effect Unit
106111
closeServerSecure = unsafeCoerce Internal.close
107112

108113
-- | https://nodejs.org/docs/latest/api/net.html#event-close
114+
-- |
115+
-- | Listen for one event, then remove the event listener.
116+
-- |
117+
-- | Returns an effect for removing the event listener before the event
118+
-- | is raised.
109119
onceCloseServerSecure :: Http2SecureServer -> Effect Unit -> Effect (Effect Unit)
110120
onceCloseServerSecure = unsafeCoerce Internal.onceServerClose
111121

112122
-- | https://nodejs.org/docs/latest/api/net.html#event-error
113123
-- |
114124
-- | the 'close' event will not be emitted directly following this event unless server.close() is manually called.
115125
-- |
116-
-- | Returns an effect for removing the event listener before the event
117-
-- | is raised.
126+
-- | Returns an effect for removing the event listener.
118127
onErrorServer :: Http2Server -> (Error -> Effect Unit) -> Effect (Effect Unit)
119128
onErrorServer = unsafeCoerce Internal.onEmitterError
120129

121130
-- | https://nodejs.org/docs/latest/api/net.html#event-error
122131
-- |
123132
-- | the 'close' event will not be emitted directly following this event unless server.close() is manually called.
124133
-- |
125-
-- | Returns an effect for removing the event listener before the event
126-
-- | is raised.
134+
-- | Returns an effect for removing the event listener.
127135
onErrorServerSecure :: Http2SecureServer -> (Error -> Effect Unit) -> Effect (Effect Unit)
128136
onErrorServerSecure = unsafeCoerce Internal.onEmitterError
129137

@@ -139,6 +147,12 @@ onErrorServerSecure = unsafeCoerce Internal.onEmitterError
139147
foreign import data ServerHttp2Session :: Type
140148

141149
-- | https://nodejs.org/docs/latest/api/http2.html#event-session
150+
-- |
151+
-- | Listen for one event, call the callback, then remove
152+
-- | the event listener.
153+
-- |
154+
-- | Returns an effect for removing the event listener before the event
155+
-- | is raised.
142156
foreign import onceSession :: Http2Server -> (ServerHttp2Session -> Effect Unit) -> Effect Unit
143157

144158
-- | https://nodejs.org/docs/latest/api/http2.html#http2sessionclosecallback
@@ -156,11 +170,14 @@ onceStream :: Http2Server -> (ServerHttp2Stream -> HeadersObject -> Flags -> Eff
156170
onceStream = unsafeCoerce Internal.onceStream
157171

158172
-- | https://nodejs.org/docs/latest/api/http2.html#event-stream
173+
-- |
174+
-- | Returns an effect for removing the event listener.
159175
onStream :: Http2Server -> (ServerHttp2Stream -> HeadersObject -> Flags -> Effect Unit) -> Effect (Effect Unit)
160176
onStream = unsafeCoerce Internal.onStream
161177

162178
-- | Listen for one event, call the callback, then remove
163179
-- | the event listener.
180+
-- |
164181
-- | Returns an effect for removing the event listener before the event
165182
-- | is raised.
166183
-- |
@@ -169,6 +186,8 @@ onceStreamSecure :: Http2SecureServer -> (ServerHttp2Stream -> HeadersObject ->
169186
onceStreamSecure = unsafeCoerce Internal.onceStream
170187

171188
-- | https://nodejs.org/docs/latest/api/http2.html#event-stream
189+
-- |
190+
-- | Returns an effect for removing the event listener.
172191
onStreamSecure :: Http2SecureServer -> (ServerHttp2Stream -> HeadersObject -> Flags -> Effect Unit) -> Effect (Effect Unit)
173192
onStreamSecure = unsafeCoerce Internal.onStream
174193

@@ -177,6 +196,11 @@ respond :: ServerHttp2Stream -> HeadersObject -> OptionsObject -> Effect Unit
177196
respond = unsafeCoerce Internal.respond
178197

179198
-- | https://nodejs.org/docs/latest/api/http2.html#event-session_1
199+
-- |
200+
-- | Listen for one event, then remove the event listener.
201+
-- |
202+
-- | Returns an effect for removing the event listener before the event
203+
-- | is raised.
180204
onceSessionSecure :: Http2SecureServer -> (ServerHttp2Session -> Effect Unit) -> Effect Unit
181205
onceSessionSecure = unsafeCoerce onceSession
182206

@@ -199,6 +223,11 @@ foreign import pushAllowed :: ServerHttp2Stream -> Effect Boolean
199223
foreign import additionalHeaders :: ServerHttp2Stream -> HeadersObject -> Effect Unit
200224

201225
-- | https://nodejs.org/docs/latest/api/http2.html#event-wanttrailers
226+
-- |
227+
-- | Listen for one event, then remove the event listener.
228+
-- |
229+
-- | Returns an effect for removing the event listener before the event
230+
-- | is raised.
202231
onceWantTrailers :: ServerHttp2Stream -> Effect Unit -> Effect (Effect Unit)
203232
onceWantTrailers = unsafeCoerce Internal.onceWantTrailers
204233

@@ -209,6 +238,11 @@ sendTrailers :: ServerHttp2Stream -> HeadersObject -> Effect Unit
209238
sendTrailers = unsafeCoerce Internal.sendTrailers
210239

211240
-- | https://nodejs.org/docs/latest/api/net.html#event-end
241+
-- |
242+
-- | Listen for one event, then remove the event listener.
243+
-- |
244+
-- | Returns an effect for removing the event listener before the event
245+
-- | is raised.
212246
onceEnd :: ServerHttp2Stream -> Effect Unit -> Effect (Effect Unit)
213247
onceEnd = unsafeCoerce Internal.onceEnd
214248

0 commit comments

Comments
 (0)