Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

How to start a separate thread from a sockets.io triggered thread

How to start a separate thread from a sockets.io triggered thread

Problem

Ok, so I am developing a multiplayer game using: Node.js, Sockets.io & Redis

Anyway players are able to create a game, then start a game, now the game logic needs to be updated about once every 10 seconds, so this is done via calling a method, that will call itself each x seconds via setTimeout.

My concern is, that when a connected client connects, creates a game (starts the setTimeout cycle) and then disconnects, this will stop any setTimeout's, therefore killing the game for all other players. Even if the setTimeout keeps being fired when a user has disconnected, I would still like to ideally run this seperately to a users socket.io connection.

Is there a simple way to start a seperate process/thread in node.js? (from a connected socket.io connection)

Problem courtesy of: Josh Mc

Solution

Depending on your purposes, maybe. For instance there's this:

http://nodejs.org/api/child_process.html

if that's not it, you might want to look at node fibers

Solution courtesy of: ControlAltDel

Discussion

View additional discussion.



This post first appeared on Node.js Recipes, please read the originial post: here

Share the post

How to start a separate thread from a sockets.io triggered thread

×

Subscribe to Node.js Recipes

Get updates delivered right to your inbox!

Thank you for your subscription

×