Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
[example] added example of by and expire reactors
- Loading branch information
Showing
2 changed files
with
62 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* client.js :: A client example showing 2 generic producers | ||
* | ||
* (C) 2013 Nodejitsu Inc. | ||
* | ||
*/ | ||
|
||
var godot = require('../lib/godot'); | ||
|
||
// | ||
// This client will expire only once you turn off this client script | ||
// | ||
godot.createClient({ | ||
type: 'tcp', | ||
producers: [ | ||
godot.producer({ | ||
host: '127.0.0.1', | ||
service: 'ohai/there', | ||
ttl: 1000 * 4 | ||
}) | ||
] | ||
}).connect(1337); | ||
|
||
// | ||
// This client will expire on the first tick | ||
// | ||
godot.createClient({ | ||
type: 'tcp', | ||
producers: [ | ||
godot.producer({ | ||
host: '127.0.0.1', | ||
service: 'new/things', | ||
ttl: 1000 * 6 | ||
}) | ||
] | ||
}).connect(1337); |
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,26 @@ | ||
/* | ||
* server.js :: An example server with fun reactor things happening | ||
* | ||
* (C) 2013 Nodejits Inc. | ||
* | ||
*/ | ||
|
||
var godot = require('../lib/godot'), | ||
expire = godot.reactor().expire(5000); | ||
|
||
// | ||
// This example shows a way to meausre two separate clients on the same | ||
// `reactor` using the power of the `by` reactor. It will create a new reactor | ||
// pipe-chain for each different 'service' in this case to easily assess the | ||
// expiration of two separate `producers`. | ||
// | ||
godot.createServer({ | ||
type: 'tcp', | ||
reactors: [ | ||
godot.reactor() | ||
.by('service', | ||
expire | ||
.console() | ||
) | ||
] | ||
}).listen(1337); |