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

Added response callback to HubServer's invoke(). #29

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from

Conversation

Evolver
Copy link

@Evolver Evolver commented Aug 30, 2017

Added response callback support to HubServer's invoke() function. Usage:

def ProcessResponse( **kwargs ):
    print "Response:", repr( kwargs )
myHub.server.invoke( "DoSomethingAndSendResponse", "arg1", "arg2", response = ProcessResponse )

@gabrielgrant
Copy link

Would very much like to see this land. @u-abramchuk are you still using/maintaining this at all?

callId = int(kwargs['I'])
if callId in self.__rspHandlers:
rspArgs = kwargs['R'] if 'R' in kwargs else {}
rspHandlers[callId](**rspArgs)
Copy link

@gabrielgrant gabrielgrant Oct 2, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe the reply is, in the general case, just a single value that should be passed directly to the function as a single parameter, not unfurled as kwargs. ie:

rspArg = kwargs['R'] if 'R' in kwargs else None 
rspHandlers[callId](rspArgs)

As it stands today, I'm getting errors from methods that don't return dicts:

Traceback (most recent call last):
  File "/home/gabriel/repos/coinbot/env/local/lib/python2.7/site-packages/gevent/greenlet.py", line 536, in run
    result = self._run(*self.args, **self.kwargs)
  File "/home/gabriel/repos/bot/env/local/lib/python2.7/site-packages/signalr/_connection.py", line 53, in wrapped_listener
    listener()
  File "/home/gabriel/repos/bot/env/local/lib/python2.7/site-packages/signalr/transports/_ws_transport.py", line 43, in _receive
    self._handle_notification(notification)
  File "/home/gabriel/repos/bot/env/local/lib/python2.7/site-packages/signalr/transports/_transport.py", line 50, in _handle_notification
    self._connection.received.fire(**data)
  File "/home/gabriel/repos/bot/env/local/lib/python2.7/site-packages/signalr/events/_events.py", line 15, in fire
    handler(*args, **kwargs)
  File "/home/gabriel/repos/bot/env/local/lib/python2.7/site-packages/signalr/hubs/_hub.py", line 25, in handle
    rspHandlers[callId](**rspArgs)
TypeError: done_subscribe() argument after ** must be a mapping, not bool
Sun Oct  1 21:13:42 2017 <Greenlet at 0x7f529dc29af0: wrapped_listener> failed with TypeError

I'm honestly not even sure that the if statement is needed -- according to a description of the wire format the R value returned by the server method should be "present if the method is not void". (see the section entitled "Server Side Hub Method Invocation Result")

@u-abramchuk
Copy link
Contributor

Hi,

unfortunately I don't have enough time to maintain the repo. So if anyone wants to take care about signalr-client-py it'll be highly appreciated.

@nkfeiyang
Copy link

Is it possible to make invoke() return a value directly? Sometimes we need a sync call to the server. The response parameter is a callback.

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

Successfully merging this pull request may close these issues.

4 participants