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

Provide synchronous API #58

Open
Jajcus opened this issue Jul 4, 2011 · 0 comments
Open

Provide synchronous API #58

Jajcus opened this issue Jul 4, 2011 · 0 comments
Labels

Comments

@Jajcus
Copy link
Owner

Jajcus commented Jul 4, 2011

The asynchronous API is efficient and flexible, but coding would be simpler with some synchronous API, with no need for callbacks defined by an application.

A code using the synchronous API would look something like this:

client.connect_s()
print("Connected!")
client.send(some_stanza)
peer_version = request_software_version_s(client, client.stream.peer)
print("{0} version: {1}".format(client.stream.peer, peer_version))
client.disconnect_s()

Some ideas for implementation:

  • for the threads running the main loop synchronous calls would be implemented by recursive calls to mainloop.loop(). A special 'SyncMethodExit' exception could be used to exit such recursive loop calls
  • other threads would just wait for some event
  • a generic wrapper could be made for asynchronous calls taking a callback and error_callback arguments. The wrapper would require access to the main loop. In case of calls which take a Client instance as the first argument client.loop could be used. Or maybe we should use thread-local storage to pass the current loop object?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant