Skip to content

Commit 71c8050

Browse files
authored
Merge pull request #19 from lpil/lp/server-close
Node.HTTP.close
2 parents 1d3890c + 052177d commit 71c8050

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

src/Node/HTTP.js

+8
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,14 @@ exports.listenImpl = function (server) {
2828
};
2929
};
3030

31+
exports.closeImpl = function (server) {
32+
return function (done) {
33+
return function () {
34+
server.close(done);
35+
};
36+
};
37+
};
38+
3139
exports.listenSocket = function (server) {
3240
return function (path) {
3341
return function (done) {

src/Node/HTTP.purs

+7
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ module Node.HTTP
88

99
, createServer
1010
, listen
11+
, close
1112
, ListenOptions
1213
, listenSocket
1314

@@ -53,10 +54,16 @@ foreign import createServer :: forall eff. (Request -> Response -> Eff (http ::
5354

5455
foreign import listenImpl :: forall eff. Server -> Int -> String -> Nullable Int -> Eff (http :: HTTP | eff) Unit -> Eff (http :: HTTP | eff) Unit
5556

57+
foreign import closeImpl :: forall eff. Server -> Eff (http :: HTTP | eff) Unit -> Eff (http :: HTTP | eff) Unit
58+
5659
-- | Listen on a port in order to start accepting HTTP requests. The specified callback will be run when setup is complete.
5760
listen :: forall eff. Server -> ListenOptions -> Eff (http :: HTTP | eff) Unit -> Eff (http :: HTTP | eff) Unit
5861
listen server opts done = listenImpl server opts.port opts.hostname (toNullable opts.backlog) done
5962

63+
-- | Close a listening HTTP server. The specified callback will be run the server closing is complete.
64+
close :: forall eff. Server -> Eff (http :: HTTP | eff) Unit -> Eff (http :: HTTP | eff) Unit
65+
close server done = closeImpl server done
66+
6067
-- | Options to be supplied to `listen`. See the [Node API](https://nodejs.org/dist/latest-v6.x/docs/api/http.html#http_server_listen_handle_callback) for detailed information about these.
6168
type ListenOptions =
6269
{ hostname :: String

0 commit comments

Comments
 (0)