简体   繁体   中英

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

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)

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM