Re: Single instance module and multithreading

From: mitchell <>
Date: Sun, 22 Feb 2009 14:05:05 -0800 (PST)


> LuaLanes looks good. I've been playing around with it, but still
> cannot get something to work yet. The idea I have is to have a socket
> listening to a port inside a lane, and when it receives something,
> calls a function defined outside the lane, passing the string
> parameter that should be executed as Lua code (e.g. '
> ("foo")'). I'm still not sure if this is possible as the Lanes
> documentation is cryptic.

I've got something working now! This is a proof of concept:

require 'socket'
require 'lanes'

local port = 3003

function received(text) print('received: '..text) end

function lane(callback)
  local socket = require 'socket'
  local server = socket.bind('localhost', port)
  local client = server:accept()
  _, _, text = client:receive()

local f = lanes.gen("*", lane)(received)

local client = socket.connect('localhost', port)

No blocking!
Received on Sun 22 Feb 2009 - 17:05:05 EST

This archive was generated by hypermail 2.2.0 : Thu 08 Mar 2012 - 11:37:31 EST