-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: [BREAKING_CHANGE] refactor Messenger (#141)
- broadcast is changed, it will send to all process - send is changed, it won't emit message Closes #28
- Loading branch information
1 parent
5900c1b
commit a65f472
Showing
7 changed files
with
108 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
'use strict'; | ||
|
||
module.exports = function(agent) { | ||
agent.messenger.on('egg-ready', () => { | ||
agent.messenger.broadcast('broadcast', { | ||
from: 'agent', | ||
pid: process.pid, | ||
}); | ||
}); | ||
|
||
agent.messenger.on('broadcast', info => { | ||
console.log('agent %s receive message from %s pid %s', process.pid, info.from, info.pid); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
'use strict'; | ||
|
||
module.exports = function(app) { | ||
app.messenger.on('egg-ready', () => { | ||
app.messenger.broadcast('broadcast', { | ||
from: 'app', | ||
pid: process.pid, | ||
}); | ||
}); | ||
|
||
app.messenger.on('broadcast', info => { | ||
console.log('app %s receive message from %s pid %s', process.pid, info.from, info.pid); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"name": "messenger-broadcast" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters