Connecting the search functions

Now we have a couple of search() functions: a public one that receives a query and returns a ReceiveChannel<Article>, and a private one that takes a feed, query, and a channel, and does the actual search. Our objective now is to connect the two of them. Let's go to the public search() function and update it so that it performs the search on each feed:

fun search(query: String) : ReceiveChannel<Article> {
val channel = Channel<Article>(150)

feeds.forEach { feed ->
launch(dispatcher) {
search(feed, channel, query)
}
}

return channel
}

Now we have a public search() function that takes a query, and returns a channel that will be used to send results as they are found in the feeds – so the caller of search() can receive articles as they become available.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.45.5