Skip to content

Commit

Permalink
Fix the FastTransformer.listen() method
Browse files Browse the repository at this point in the history
  • Loading branch information
cedx committed Nov 4, 2024
1 parent 521d013 commit 46db498
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Cakefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{spawnSync} = require "node:child_process"
{readdirSync, rmSync} = require "node:fs"
{extname, join} = require "node:path"
{join} = require "node:path"
{env} = require "node:process"
pkg = require "./package.json"

Expand Down
13 changes: 6 additions & 7 deletions src/fast_transformer.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ export class FastTransformer
# Starts the underlying PHP process and begins accepting connections.
listen: -> if @_process? then Promise.resolve @_port else
@_port = await @_getPort()
args = ["-S", "127.0.0.1:#{@_port}", "-t", join(import.meta.dirname, "../www")]
new Promise (fulfill, reject) =>
spawn @_executable, args, stdio: ["ignore", "pipe", "ignore"]
args = ["-S", "127.0.0.1:#{@_port}", "-t", join(import.meta.dirname, "../www")]
@_process = spawn @_executable, args, stdio: ["ignore", "pipe", "ignore"]
.on "error", reject
.on "spawn", => setTimeout (=> fulfill @_port), 1000

Expand All @@ -45,8 +45,7 @@ export class FastTransformer

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

0 comments on commit 46db498

Please sign in to comment.