npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

sugos

v2.2.10

Published

A high-level RPC framework to make remote controlling super easy.

Downloads

2

Readme

Build Status npm Version JS Standard

A high-level RPC framework to make remote controlling super easy.

What you can do with SUGOS is:

  1. Declare a function on a client.
  2. Call the function from another client.

SUGOS magically connect two clients on remote networks, and provides pseudo function interface as if they are on the same environment.

It also supports event driven architecture. You can emit or listen remote events in Node.js events style. This feature greatly helps you to build applications for IoT or Cloud Robotics.

Table of Contents

Requirements

Installation

# Install sugos as a global module
$ npm install -g sugos

Getting Started

3 steps to be getting started

  1. Setup SUGO-Hub
  2. Declare modules on SUGO-Actor
  3. Access to modules from SUGO-Caller

Setup SUGO-Hub

Setup a SUGO-Hub server for actors and callers.

#!/usr/bin/env node
/**
 * This is an example of SUGO-Hub
 * @see https://github.com/realglobe-Inc/sugo-hub
 */
'use strict'

const sugoHub = require('sugo-hub')
const co = require('co')

co(function * () {
  // Start sugo-hub server
  let hub = yield sugoHub({}).listen(3000)
  console.log(`SUGO Hub started at port: ${hub.port}`)
}).catch((err) => console.error(err))

Declare modules on SUGO-Actor

Create a SUGO-Actor instance and declare modules. Then, connect to the hub server.

#!/usr/bin/env

/**
 * This is an example of SUGO-Actor
 * @see https://github.com/realglobe-Inc/sugo-actor
 */
'use strict'

const sugoActor = require('sugo-actor')
const { Module } = sugoActor
const co = require('co')

co(function * () {
  let actor = sugoActor({
    /** Host of hub to connect */
    hostname: 'localhost',
    port: 3000,
    /** Name to identify this actor on the hub */
    key: 'my-actor-01',
    /** Modules to provide */
    modules: {
      // Example of a simple call-return function module
      tableTennis: new Module({
        ping (pong = 'default pong!') {
          return co(function * () {
            /* ... */
            return `"${pong}" from actor!` // Return to the remote caller
          })
        }
      }),
      // Load plugin module
      timeBomb: require('./example-time-bomb-module')({})
    }
  })
  yield actor.connect() // Connect to the hub server
}).catch((err) => console.error(err))

Access to modules from SUGO-Caller

Create a SUGO-Caller instance and connect to the actor with key. Then get access to modules and call functions as you like.

#!/usr/bin/env

/**
 * This is an example of SUGO-Caller
 * @see https://github.com/realglobe-Inc/sugo-caller
 */
'use strict'

const sugoCaller = require('sugo-caller')
const co = require('co')

co(function * () {
  let caller = sugoCaller({
    // Host of hub to connect
    hostname: 'localhost',
    port: 3000
  })
  // Connect to an actor with key
  let actor01 = yield caller.connect('my-actor-01')

  // Using call-return function
  {
    let tableTennis = actor01.get('tableTennis')
    let pong = yield tableTennis.ping('hey!')
    console.log(pong) // -> `"hey!" from actor!`
  }

}).catch((err) => console.error(err))

Advanced Usage

Using Event-Emit Interface

On actors, each module provides EventEmitter interface like .on(ev, handler) and .emit(ev, data) functions.

/**
 * This is an example module
 */
'use strict'

const co = require('co')
const { Module } = require('sugo-actor')

class TimeBomb extends Module {
  // Example of event emitting function
  countDown (count) {
    const s = this
    return co(function * () {
      let abort = () => { count = -1 }
      s.on('abort', abort) // Listen to events from the caller
      while (count > 0) {
        count--
        s.emit('tick', { count }) // Emit an event to the caller
        yield new Promise((resolve) =>
          setTimeout(() => resolve(), 1000)
        )
      }
      s.off('abort', abort) // Remove event listener
      return count === -1 ? 'hiss...' : 'booom!!!'
    })
  }
}

function newTimeBomb (...args) {
  return new TimeBomb(...args)
}

module.exports = newTimeBomb // Pass factory method
#!/usr/bin/env

/**
 * This is an example of SUGO-Caller to use event emit
 */
'use strict'

const sugoCaller = require('sugo-caller')
const co = require('co')

co(function * () {
  let caller = sugoCaller({ /* ... */ })
  let actor01 = yield caller.connect('my-actor-01')

  // Using event emitting interface
  {
    let timeBomb = actor01.get('timeBomb')
    let tick = (data) => console.log(`tick: ${data.count}`)
    timeBomb.on('tick', tick) // Add listener
    let booom = yield timeBomb.countDown(10)
    console.log(booom)
    timeBomb.off('tick', tick) // Remove listener
  }
}).catch((err) => console.error(err))

Tutorials

API Docs

Related Packages

There are a bunch of related package and there are listed in sugos-index page

Contributors

License

This software is released under the Apache-2.0 License.

Links