Skip to content

Node.HTTP.close #19

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 6, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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