GithubHelp home page GithubHelp logo

web5design / thoonk.js Goto Github PK

View Code? Open in Web Editor NEW

This project forked from andyet/thoonk.js

0.0 3.0 0.0 247 KB

Persistent (and fast!) push feeds, queues, and jobs leveraging Redis

Home Page: http://thoonk.com

License: Other

thoonk.js's Introduction

Thoonk

What is Thoonk?

Thoonk is a persistent (and fast!) framework for Redis backed live data and objects, such as push feeds, queues, and jobs.

Thoonk lets you create a Model whose methods are mapped to Redis Lua scripts, and can listen for and emit events using Redis pubsub channels.

Since all of the actual logic for the model is written in Lua, Thoonk wrappers for other languages can be written which can interoperate with thoonk.js, such as the Python version thoonk.py.

Installing

npm install thoonk

By itself, Thoonk is just a small framework for marshalling and setting up subscriptions and loading Lua scripts into Redis. To see Thoonk in action you will want to look at the examples for how to build a Thoonk backed model.

Example

First, we create our model definition in examples/helloworld.js:

var ThoonkInterface = require('thoonk').ThoonkBaseInterface;


function HelloWorld(thoonk) {
    // Link the HelloWorld object to a thoonk connection.
    ThoonkInterface.call(this, thoonk);
}

HelloWorld.prototype = Object.create(ThoonkInterface.prototype);

// Set a unique type name for our HelloWorld model
HelloWorld.prototype.objtype = 'helloworld'; 

// Specify where to load Lua scripts from for our model
HelloWorld.prototype.scriptdir = __dirname + '/scripts';

(function () {

    this.greet = function (firstName, lastName, cb) {
        this.runScript('greet', [firstName, lastName], cb);
    };

}).call(HelloWorld.prototype);


module.exports = HelloWorld;

Then we create the Lua script we need in examples/scripts/greet.lua:

local firstName, lastName = unpack(ARGV);

return "Hello, " .. firstName .. " " .. lastName;

And finally, when we want to use our HelloWorld model:

var thoonk = require('thoonk').createClient();
var HelloWorld = require('helloworld');

thoonk.registerInterface('HelloWorld', HelloWorld, function () {
    // All scripts have been loaded and event subscriptions initialized.

    var hello = thoonk.objects.HelloWorld();

    hello.greet('Arthur', 'Dent', function (err, result) {
        if (err) {
            console.error(err);
        } else {
            console.log(result);
            // >>> Hello, Arthur Dent
        }
    });
});

Addons

License

MIT

Created By

If you like this, follow: @fritzy on twitter.

thoonk.js's People

Contributors

fritzy avatar legastero avatar henrikjoreteg avatar jacwright avatar ike avatar

Watchers

JT5D avatar James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.