-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(core): Introduce groups joinable via NamedGroup
- Loading branch information
1 parent
8996117
commit b65b5a8
Showing
20 changed files
with
436 additions
and
492 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,18 @@ | ||
const { Exchange } = require('../../packages/core'); | ||
const { NamedGroup } = require('../../packages/core'); | ||
|
||
module.exports = async function(net) { | ||
|
||
let counter = 0; | ||
|
||
const exchange = net.createExchange('counter'); | ||
exchange.onNodeAvailable(node => { | ||
const group = new NamedGroup(net, 'counter'); | ||
group.onNodeAvailable(node => { | ||
node.send('hello', { counter: counter }) | ||
.catch(e => console.log('Timed out sending hello')); | ||
}) | ||
|
||
await exchange.join(); | ||
await group.join(); | ||
|
||
// Increment and broadcast counter to all nodes every five seconds | ||
setInterval(() => { | ||
exchange.broadcast('counter', { current: ++counter }); | ||
group.broadcast('counter', { current: ++counter }); | ||
}, 5000); | ||
|
||
} |
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
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 was deleted.
Oops, something went wrong.
Oops, something went wrong.