Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Context argument for stream write operation #12

Closed
moteus opened this issue Mar 6, 2015 · 0 comments
Closed

Context argument for stream write operation #12

moteus opened this issue Mar 6, 2015 · 0 comments

Comments

@moteus
Copy link
Owner

moteus commented Mar 6, 2015

This may be helpful to implement wrapper classes

E.g. SSL socket

function SSLSocket:write(msg,cb)
  -- here we have to make closure for each call 
  -- (or use table to cache them with `cb` as key)
  self._sock:write(msg, function(_, ...) cb(self, ...) end)
end

I suggest allow pass additional context argument to write function

function SSLSocket:__init()
  self._on_write_done = function(_, err, cb) cb(self, err) end
end

function SSLSocket:write(msg,cb)
  -- here we can use same closure for all calls
  self._sock:write(msg, self._on_write_done, cb)
end

Add context to other callbacks I see no reason because they do not call as often as write.
But this adds some inconsistent to API. Also I do not think it possible make multiple variables as context because for this we need some table and user code can do this by self.

@moteus moteus closed this as completed in 9e93152 Mar 8, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant