Skip to content

Commit

Permalink
fixed #1
Browse files Browse the repository at this point in the history
  • Loading branch information
Akumzy committed Aug 15, 2019
1 parent 3567965 commit b2eb519
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 35 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@
# Output of the go coverage tool, specifically when used with LiteIDE
*.out

example/node_modules
test/node_modules
package-lock.json
example/example
test/test
23 changes: 0 additions & 23 deletions example/node.js

This file was deleted.

29 changes: 19 additions & 10 deletions ipc.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,11 @@ func (ipc IPC) Start() {
}()
for {
reader := bufio.NewReader(os.Stdin)
text, _ := reader.ReadString('\n')
text, err := reader.ReadString('\n')
if err != nil {
log.Println(err)
continue
}
if text != "" {
var payload payloadReceive
text = strings.TrimSuffix(text, "\n")
Expand All @@ -144,16 +148,21 @@ func (ipc IPC) Start() {
if payload.Event == "___EXIT___" {
os.Exit(0)
}
if payload.SR {
for _, handler := range ipc.receiveSendListerners[payload.Event] {
replyChannel := payload.Event + "___RC___"
handler(replyChannel, payload.Data)
}
} else {
for _, handler := range ipc.receiveListerners[payload.Event] {
handler(payload.Data)
// Run the handlers in a goroutine to prevent
// https://github.com/Akumzy/ipc/issues/1
go func() {

if payload.SR {
for _, handler := range ipc.receiveSendListerners[payload.Event] {
replyChannel := payload.Event + "___RC___"
handler(replyChannel, payload.Data)
}
} else {
for _, handler := range ipc.receiveListerners[payload.Event] {
handler(payload.Data)
}
}
}
}()
}

}
Expand Down
File renamed without changes.
25 changes: 25 additions & 0 deletions test/node.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
const IPC = require('ipc-node-go')
const ipc = new IPC('./test')
ipc.init()

ipc.on('log', console.log)
// Log all error from stderr
ipc.on('error', console.error)
// ipc.on('ping', () => {
// console.log(new Date())
// })

//
ipc.send('who', { name: 'Akuma Nodejs' })
// send and receive and an acknowledgement

// listen for event and reply to the channel
ipc.onReceiveAnSend('hola', (channel, data) => {
console.log(data)
ipc.send(channel, 'cool thanks')
})
// setInterval(() => {
// ipc.sendAndReceive('yoo', 'Hello, how are you doing?', (err, d) => {
// err ? console.error(err) : console.log(d)
// })
// }, 20000)
File renamed without changes.
File renamed without changes.

0 comments on commit b2eb519

Please sign in to comment.