Skip to content

Commit

Permalink
Merge pull request #19 from lpil/lp/server-close
Browse files Browse the repository at this point in the history
Node.HTTP.close
  • Loading branch information
paf31 authored Nov 6, 2017
2 parents 1d3890c + 052177d commit 71c8050
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/Node/HTTP.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@ exports.listenImpl = function (server) {
};
};

exports.closeImpl = function (server) {
return function (done) {
return function () {
server.close(done);
};
};
};

exports.listenSocket = function (server) {
return function (path) {
return function (done) {
Expand Down
7 changes: 7 additions & 0 deletions src/Node/HTTP.purs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ module Node.HTTP

, createServer
, listen
, close
, ListenOptions
, listenSocket

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

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

foreign import closeImpl :: forall eff. Server -> Eff (http :: HTTP | eff) Unit -> Eff (http :: HTTP | eff) Unit

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

-- | Close a listening HTTP server. The specified callback will be run the server closing is complete.
close :: forall eff. Server -> Eff (http :: HTTP | eff) Unit -> Eff (http :: HTTP | eff) Unit
close server done = closeImpl server done

-- | 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.
type ListenOptions =
{ hostname :: String
Expand Down

0 comments on commit 71c8050

Please sign in to comment.