Last active
February 7, 2017 06:33
-
-
Save okunishinishi/f51a4ab5dcbdb459792d0f4d72257094 to your computer and use it in GitHub Desktop.
[SUGOS] チュートリアル00 - SUGOSことはじめ ref: http://qiita.com/okunishinishi@github/items/088b0c22e6e3d2b0afe6
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
'use strict' | |
const co = require('co') | |
const sugoActor = require('sugo-actor') | |
const { Module } = sugoActor | |
co(function * () { | |
// Define a module with methods | |
let tableTennis = new Module({ | |
ping (pong) { | |
return `"${pong}" from actor!` | |
} | |
}) | |
// Create an actor client instance | |
let actor = sugoActor({ | |
host: 'example.sugo-hub.com', | |
key: 'my-actor-01', | |
modules: { tableTennis } | |
}) | |
// Connect to hub server | |
yield actor.connect() | |
}).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
'use strict' | |
const sugoCaller = require('sugo-caller') | |
const co = require('co') | |
co(function * () { | |
let caller = sugoCaller({ | |
host: 'example.sugo-hub.com' | |
}) | |
// Connect to an actor with key | |
let actor01 = yield caller.connect('my-actor-01') | |
{ | |
// Get a module of the actor | |
let tableTennis = actor01.get('tableTennis') | |
let pong = yield tableTennis.ping('hey!') | |
console.log(pong) // -> `"hey!" from call!` | |
} | |
}).catch((err) => console.error(err)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment