diff --git a/lib/src/common/search_service.dart b/lib/src/common/search_service.dart index b9bc5da5..d3c451b8 100644 --- a/lib/src/common/search_service.dart +++ b/lib/src/common/search_service.dart @@ -20,11 +20,14 @@ class SearchService extends Service { var controller = StreamController(); var isFirst = true; - - PaginationHelper(_github) - .fetchStreamed("GET", "/search/repositories", - params: params, pages: pages) - .listen((response) { + final stream = PaginationHelper(_github).fetchStreamed( + "GET", + "/search/repositories", + params: params, + pages: pages, + ); + + return stream.expand((response) { if (response.statusCode == 403 && response.body.contains("rate limit") && isFirst) { @@ -36,15 +39,13 @@ class SearchService extends Service { var input = jsonDecode(response.body); if (input['items'] == null) { - return; + return []; } var items = input['items'] as List; - items.map((item) => Repository.fromJSON(item)).forEach(controller.add); - }).onDone(controller.close); - - return controller.stream; + return items.map((item) => Repository.fromJSON(item)); + }); } /// Search through code for a given [query]. @@ -139,13 +140,11 @@ class SearchService extends Service { params["per_page"] = perPage.toString(); - var controller = StreamController(); - var isFirst = true; + final stream = PaginationHelper(_github) + .fetchStreamed("GET", "/search/users", params: params, pages: pages); - PaginationHelper(_github) - .fetchStreamed("GET", "/search/users", params: params, pages: pages) - .listen((response) { + return stream.expand((response) { if (response.statusCode == 403 && response.body.contains("rate limit") && isFirst) { @@ -157,14 +156,11 @@ class SearchService extends Service { var input = jsonDecode(response.body); if (input['items'] == null) { - return; + return []; } var items = input['items'] as List; - - items.map((item) => User.fromJson(item)).forEach(controller.add); - }).onDone(controller.close); - - return controller.stream; + return items.map((item) => User.fromJson(item)); + }); } } diff --git a/test/experiment/search.dart b/test/experiment/search.dart index 84b5f366..cddd1328 100755 --- a/test/experiment/search.dart +++ b/test/experiment/search.dart @@ -1,10 +1,16 @@ import "package:github/server.dart"; -void main() { +void main() async { var github = createGitHubClient(); - github.search.repositories("github").listen((repo) { - print( - "${repo.fullName}: ${repo.description.isNotEmpty ? repo.description : "No Description"}"); - }).onDone(() => github.dispose()); + try { + for (var i = 0; i < 10; i++) { + // keep executing until we reach the rate limiter + final stream = github.search.repositories("github"); + final all = await stream.toList(); + print(all.length); + } + } catch (e) { + print(e); + } } pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy