当前位置: 首页>>代码示例>>Python>>正文


Python ObservableDeferred.addBoth方法代码示例

本文整理汇总了Python中synapse.util.ObservableDeferred.addBoth方法的典型用法代码示例。如果您正苦于以下问题:Python ObservableDeferred.addBoth方法的具体用法?Python ObservableDeferred.addBoth怎么用?Python ObservableDeferred.addBoth使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在synapse.util.ObservableDeferred的用法示例。


在下文中一共展示了ObservableDeferred.addBoth方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: set

# 需要导入模块: from synapse.util import ObservableDeferred [as 别名]
# 或者: from synapse.util.ObservableDeferred import addBoth [as 别名]
    def set(self, key, deferred):
        """Set the entry for the given key to the given deferred.

        *deferred* should run its callbacks in the sentinel logcontext (ie,
        you should wrap normal synapse deferreds with
        logcontext.run_in_background).

        Can return either a new Deferred (which also doesn't follow the synapse
        logcontext rules), or, if *deferred* was already complete, the actual
        result. You will probably want to make_deferred_yieldable the result.

        Args:
            key (hashable):
            deferred (twisted.internet.defer.Deferred[T):

        Returns:
            twisted.internet.defer.Deferred[T]|T: a new deferred, or the actual
                result.
        """
        result = ObservableDeferred(deferred, consumeErrors=True)
        self.pending_result_cache[key] = result

        def remove(r):
            if self.timeout_sec:
                self.clock.call_later(
                    self.timeout_sec,
                    self.pending_result_cache.pop, key, None,
                )
            else:
                self.pending_result_cache.pop(key, None)
            return r

        result.addBoth(remove)
        return result.observe()
开发者ID:rubo77,项目名称:synapse,代码行数:36,代码来源:response_cache.py

示例2: wait_for_previous_lookups

# 需要导入模块: from synapse.util import ObservableDeferred [as 别名]
# 或者: from synapse.util.ObservableDeferred import addBoth [as 别名]
    def wait_for_previous_lookups(self, server_names, server_to_deferred):
        """Waits for any previous key lookups for the given servers to finish.

        Args:
            server_names (list): list of server_names we want to lookup
            server_to_deferred (dict): server_name to deferred which gets
                resolved once we've finished looking up keys for that server
        """
        while True:
            wait_on = [
                self.key_downloads[server_name]
                for server_name in server_names
                if server_name in self.key_downloads
            ]
            if wait_on:
                with PreserveLoggingContext():
                    yield defer.DeferredList(wait_on)
            else:
                break

        for server_name, deferred in server_to_deferred.items():
            d = ObservableDeferred(preserve_context_over_deferred(deferred))
            self.key_downloads[server_name] = d

            def rm(r, server_name):
                self.key_downloads.pop(server_name, None)
                return r

            d.addBoth(rm, server_name)
开发者ID:pombredanne,项目名称:synapse-2,代码行数:31,代码来源:keyring.py

示例3: set

# 需要导入模块: from synapse.util import ObservableDeferred [as 别名]
# 或者: from synapse.util.ObservableDeferred import addBoth [as 别名]
    def set(self, key, deferred):
        result = ObservableDeferred(deferred, consumeErrors=True)
        self.pending_result_cache[key] = result

        def remove(r):
            self.pending_result_cache.pop(key, None)
            return r

        result.addBoth(remove)
        return result.observe()
开发者ID:0-T-0,项目名称:synapse,代码行数:12,代码来源:response_cache.py

示例4: set

# 需要导入模块: from synapse.util import ObservableDeferred [as 别名]
# 或者: from synapse.util.ObservableDeferred import addBoth [as 别名]
    def set(self, key, deferred):
        result = ObservableDeferred(deferred, consumeErrors=True)
        self.pending_result_cache[key] = result

        def remove(r):
            if self.timeout_sec:
                self.clock.call_later(
                    self.timeout_sec,
                    self.pending_result_cache.pop, key, None,
                )
            else:
                self.pending_result_cache.pop(key, None)
            return r

        result.addBoth(remove)
        return result.observe()
开发者ID:mebjas,项目名称:synapse,代码行数:18,代码来源:response_cache.py


注:本文中的synapse.util.ObservableDeferred.addBoth方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。