How to use the riffle.utils function in Riffle

To help you get started, we’ve selected a few Riffle examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github exis-io / Exis / python / pyRiffle / riffle / crust.py View on Github external
args = [] if args is None else args

            # When the channel that feeds the Receive function closes, 0 is returned
            # This is currently automagic and happened to work on accident, but consider
            # a more explicit close
            if i == 0:
                break

            if i in self.deferreds:
                d = self.deferreds[i]
                del self.deferreds[d.cb]
                del self.deferreds[d.eb]

                # Special Python case-- if this is an errback construct an excepction
                if i == d.eb:
                    args = utils.Error(*args)

                # Deferreds are always emitted by async methods. If the user called .wait()
                # then the deferred instantiates a greenlet as .green. Resume that greenlet.
                # If that greenlet emits another deferred the user has called .wait() again.
                if d.green is not None:
                    d = d.green.switch(args)
                    if d is not None:
                        self.deferreds[d.cb], self.deferreds[d.eb] = d, d

            elif i in self.handlers:
                handler, canReturn = self.handlers[i]

                if canReturn:
                    resultID = args.pop(0)

                # Consolidated handlers into one
github exis-io / Exis / python / pyRiffle / riffle / crust.py View on Github external
def _setHandler(self, endpoint, handler, coreFunction, doesReturn):
        '''
        Register or Subscribe. Invokes targetFunction for the given endpoint and handler.

        :param coreFunction: the intended core function, either Subscribe or Register
        :param doesReturn: True if this handler can return a value (is a registration)
        '''

        d, handlerId = Deferred(), utils.newID()
        self.app.deferreds[d.cb], self.app.deferreds[d.eb] = d, d
        self.app.handlers[handlerId] = handler, doesReturn

        coreFunction(endpoint, d.cb, d.eb, handlerId, cumin.reflect(handler))
        return d