2017-01-04 2 views
0

コードはここにある:未来はどのようにObservableに自動的に変換されますか?

https://github.com/ReactiveX/RxPY/blob/master/examples/autocomplete/autocomplete_asyncio.py#L63

searcher = query.flat_map_latest(search_wikipedia) 

def search_wikipedia(term): 
    """Search Wikipedia for a given term""" 
    url = 'http://en.wikipedia.org/w/api.php' 

    params = { 
     "action": 'opensearch', 
     "search": term, 
     "format": 'json' 
    } 
    # Must set a user agent for non-browser requests to Wikipedia 
    user_agent = "RxPY/1.0 (https://github.com/dbrattli/RxPY; [email protected]) Tornado/4.0.1" 

    url = url_concat(url, params) 

    http_client = AsyncHTTPClient() 
    return http_client.fetch(url, method='GET', user_agent=user_agent) 

Observable.flat_map_latestは()観察を返すべき関数を受け入れながら機能は、未来を返すsearch_wikipedia。

私の質問は、 futureはsearch_wikipedia()によって自動的にObservableに変換されましたか? FutureをObservableに変換できるObservable.from_future()があります。しかし、明示的に呼び出されるべきです。

答えて

1

回答が得られました。 Observer.flat_map()パラメータタイプを検出し、from_future()を呼び出した場合は

関連する問題