當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。