Skip to content

Commit 46db498

Browse files
author
Cédric Belin
committed
Fix the FastTransformer.listen() method
1 parent 521d013 commit 46db498

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-8
lines changed

Cakefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{spawnSync} = require "node:child_process"
22
{readdirSync, rmSync} = require "node:fs"
3-
{extname, join} = require "node:path"
3+
{join} = require "node:path"
44
{env} = require "node:process"
55
pkg = require "./package.json"
66

src/fast_transformer.coffee

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ export class FastTransformer
2727
# Starts the underlying PHP process and begins accepting connections.
2828
listen: -> if @_process? then Promise.resolve @_port else
2929
@_port = await @_getPort()
30-
args = ["-S", "127.0.0.1:#{@_port}", "-t", join(import.meta.dirname, "../www")]
3130
new Promise (fulfill, reject) =>
32-
spawn @_executable, args, stdio: ["ignore", "pipe", "ignore"]
31+
args = ["-S", "127.0.0.1:#{@_port}", "-t", join(import.meta.dirname, "../www")]
32+
@_process = spawn @_executable, args, stdio: ["ignore", "pipe", "ignore"]
3333
.on "error", reject
3434
.on "spawn", => setTimeout (=> fulfill @_port), 1000
3535

@@ -45,8 +45,7 @@ export class FastTransformer
4545

4646
# Gets an ephemeral TCP port chosen by the system.
4747
_getPort: -> new Promise (fulfill, reject) ->
48-
socket = createServer().on "error", reject
49-
socket.unref()
50-
socket.listen host: "127.0.0.1", port: 0, ->
51-
{port} = socket.address()
52-
socket.close -> fulfill port
48+
server = createServer().unref().on "error", reject
49+
server.listen host: "127.0.0.1", port: 0, ->
50+
{port} = server.address()
51+
server.close -> fulfill port

0 commit comments

Comments
 (0)