Skip to content

Commit

Permalink
Use a single node process (#43)
Browse files Browse the repository at this point in the history
  • Loading branch information
callumevans authored Nov 11, 2024
1 parent e149477 commit 1dd0bbd
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ samples/**/*terraform.tfstate*
/samples/**/*-package.zip
.terrable/
dist/
__debug_bin*
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"request": "attach",
"port": 9229,
"restart": true,
"continueOnAttach": true,
"continueOnAttach": false,
"address": "localhost",
"localRoot": "${workspaceFolder}",
"remoteRoot": "${workspaceFolder}",
Expand Down
2 changes: 1 addition & 1 deletion offline/handler_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func ServeHandler(handlerInstance *HandlerInstance, r *mux.Router) {
inputFiles := handlerInstance.CompileHandler()
go handlerInstance.WatchForChanges(inputFiles)

np, err := NewNodeProcess()
np, err := GetNodeProcess()

if err != nil {
panic(err)
Expand Down
22 changes: 21 additions & 1 deletion offline/node_process.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,27 @@ type NodeProcess struct {
//go:embed node_handler_wrapper.js
var NODE_HANDLER_WRAPPER string

func NewNodeProcess() (*NodeProcess, error) {
var (
nodeProcess *NodeProcess
nodeProcessSyncOnce sync.Once
nodeProcessInitError error
)

func GetNodeProcess() (*NodeProcess, error) {
nodeProcessSyncOnce.Do(func() {
newNodeProcess, err := initNodeProcess()
nodeProcessInitError = err
nodeProcess = newNodeProcess
})

if nodeProcessInitError != nil {
return nil, nodeProcessInitError
}

return nodeProcess, nil
}

func initNodeProcess() (*NodeProcess, error) {
cmd := exec.Command("node", "--inspect=9229", "-e", NODE_HANDLER_WRAPPER)

stdin, err := cmd.StdinPipe()
Expand Down
2 changes: 1 addition & 1 deletion terrable_build
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version = 0.1.7
version = 0.1.8

0 comments on commit 1dd0bbd

Please sign in to comment.