Last active
February 7, 2017 06:37
-
-
Save okunishinishi/c3032759d0f6dd5e05b53ea1d545025e to your computer and use it in GitHub Desktop.
[SUGOS] チュートリアル01 - Hello Worldしてみる ref: http://qiita.com/okunishinishi@github/items/65c0336b0aee9c29cc65
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
mkdir sugos-tutorial-01 | |
cd sugos-tutorial-01 | |
npm init -y | |
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
npm install sugo-actor sugo-caller sugo-hub co asleep -S |
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
#!/usr/bin/env node | |
/** | |
* Start hub server | |
* @see https://github.com/realglobe-Inc/sugo-hub | |
*/ | |
'use strict' | |
const sugoHub = require('sugo-hub') | |
const co = require('co') | |
co(function * () { | |
let hub = sugoHub({}) | |
yield hub.listen(3000) | |
console.log(`SUGO Cloud started at port: ${hub.port}`) | |
}).catch((err) => { | |
console.error(err) | |
process.exit(1) | |
}) | |
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
node ./hub.js |
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
/** | |
* Sample of module with simple call-return function | |
* @module tableTennis | |
* @see https://github.com/realglobe-Inc/sugo-module-base#usage | |
*/ | |
'use strict' | |
const { Module } = require('sugo-actor') | |
const co = require('co') | |
const asleep = require('asleep') | |
// Create a new module | |
const tableTennis = new Module({ | |
ping (message = '') { | |
// Just wait 500ms and return pong. | |
return co(function * () { | |
yield asleep(500) | |
return `pong! ${message}` | |
}) | |
} | |
}) | |
module.exports = tableTennis | |
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
#!/usr/bin/env node | |
/** | |
* Connect actor | |
*/ | |
'use strict' | |
const sugoActor = require('sugo-actor') | |
const co = require('co') | |
const tableTennis = require('./modules/table-tennis') | |
co(function * () { | |
let actor = sugoActor({ | |
host: 'localhost:3000', | |
key: 'my-actor-01', | |
/** Modules to load */ | |
modules: { | |
tableTennis | |
} | |
}) | |
// Connect to hub | |
yield actor.connect() | |
console.log(`Actor connected to: ${actor.socket.io.uri}`) | |
}).catch((err) => console.error(err)) | |
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
node ./actor.js |
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
#!/usr/bin/env node | |
/** | |
* Use sugo caller | |
* @see https://github.com/realglobe-Inc/sugo-caller#readme | |
*/ | |
'use strict' | |
const sugoCaller = require('sugo-caller') | |
const co = require('co') | |
co(function * () { | |
let caller = sugoCaller({ | |
host: 'localhost:3000' | |
}) | |
// Connect to actor | |
let myActor01 = yield caller.connect('my-actor-01') | |
let tableTennis = myActor01.get('tableTennis') | |
let pong = yield tableTennis.ping('hello world!') | |
console.log(`Pong from myActor01/tableTennis: "${pong}"`) | |
}).catch((err) => console.error(err)) | |
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
node ./caller.js |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment