Commit 2438d4fa authored by Denis Bilenko's avatar Denis Bilenko

rename Greenlet.link()'s argument to 'callback'

Previously it was called 'receiver'. Also link_exception() had
a default value for it which was None, but it did not work,
since linking to current greenlet feature was removed some time ago.

Section on spawn_link was removed from doc since these functions have
been gone for some time as well.

Closes #244.
parent bc03e2fd
......@@ -38,9 +38,9 @@ It also a good idea to override :meth:`__str__`: if :meth:`_run` raises an excep
.. automethod:: Greenlet.join
.. automethod:: Greenlet.get
.. automethod:: Greenlet.kill(exception=GreenletExit, block=False, timeout=None)
.. automethod:: Greenlet.link(receiver=None)
.. automethod:: Greenlet.link_value(receiver=None)
.. automethod:: Greenlet.link_exception(receiver=None)
.. automethod:: Greenlet.link(callback)
.. automethod:: Greenlet.link_value(callback)
.. automethod:: Greenlet.link_exception(callback)
.. automethod:: Greenlet.unlink
......@@ -79,21 +79,6 @@ Spawn helpers
As this returns a raw greenlet, it does not have all the useful methods that
:class:`gevent.Greenlet` has and should only be used as an optimization.
.. function:: spawn_link(function, *args, **kwargs)
spawn_link_value(function, *args, **kwargs)
spawn_link_exception(function, *args, **kwargs)
This are the shortcuts for::
g = spawn(function, *args, **kwargs)
g.link() # or g.link_value() or g.link_exception()
As :meth:`Greenlet.link` without argument links to the current greenlet, a :class:`gevent.greenlet.LinkedExited`
exception will be raised if the newly spawned greenlet exits. It is not meant as a way of inter-greenlet communication
but more of a way to assert that a background greenlet is running at least as long as the current greenlet.
See :meth:`Greenlet.link`, :meth:`Greenlet.link_value` and :meth:`Greenlet.link_exception` for details.
Useful general functions
------------------------
......
......@@ -346,28 +346,28 @@ class Greenlet(greenlet):
if self.ready() and self._links and not self._notifier:
self._notifier = self.parent.loop.run_callback(self._notify_links)
def link(self, receiver, SpawnedLink=SpawnedLink):
def link(self, callback, SpawnedLink=SpawnedLink):
"""Link greenlet's completion to a callable.
The *receiver* will be called with this instance as an argument
The *callback* will be called with this instance as an argument
once this greenlet's dead. A callable is called in its own greenlet.
"""
self.rawlink(SpawnedLink(receiver))
self.rawlink(SpawnedLink(callback))
def unlink(self, receiver):
"""Remove the receiver set by :meth:`link` or :meth:`rawlink`"""
def unlink(self, callback):
"""Remove the callback set by :meth:`link` or :meth:`rawlink`"""
try:
self._links.remove(receiver)
self._links.remove(callback)
except ValueError:
pass
def link_value(self, receiver, SpawnedLink=SuccessSpawnedLink):
"""Like :meth:`link` but *receiver* is only notified when the greenlet has completed successfully"""
self.link(receiver=receiver, SpawnedLink=SpawnedLink)
def link_value(self, callback, SpawnedLink=SuccessSpawnedLink):
"""Like :meth:`link` but *callback* is only notified when the greenlet has completed successfully"""
self.link(callback, SpawnedLink=SpawnedLink)
def link_exception(self, receiver=None, SpawnedLink=FailureSpawnedLink):
"""Like :meth:`link` but *receiver* is only notified when the greenlet dies because of unhandled exception"""
self.link(receiver=receiver, SpawnedLink=SpawnedLink)
def link_exception(self, callback, SpawnedLink=FailureSpawnedLink):
"""Like :meth:`link` but *callback* is only notified when the greenlet dies because of unhandled exception"""
self.link(callback, SpawnedLink=SpawnedLink)
def _notify_links(self):
while self._links:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment