Skip to content

Conversation

@lambdalisue
Copy link
Member

@lambdalisue lambdalisue commented Oct 14, 2024

Transform an async iterable into a repeatable async iterable. It caches the values of the original iterable so that it can be replayed. Useful for replaying the costly async iterable.

import { repeatable } from "@core/iterutil/async/repeatable";
import { assertEquals } from "@std/assert";

const origin = (async function* () {
  yield 1;
  yield 2;
  yield 3;
})();
const iter = repeatable(origin);
assertEquals(await Array.fromAsync(iter), [1, 2, 3]);
assertEquals(await Array.fromAsync(iter), [1, 2, 3]); // iter can be replayed
assertEquals(await Array.fromAsync(origin), []); // origin is already consumed

@codecov
Copy link

codecov bot commented Oct 14, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (85fd83b) to head (b0f587f).
Report is 6 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##              main       #23   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          117       118    +1     
  Lines         1370      1409   +39     
  Branches       215       222    +7     
=========================================
+ Hits          1370      1409   +39     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@lambdalisue lambdalisue merged commit 18c3d76 into main Oct 14, 2024
6 checks passed
@lambdalisue lambdalisue deleted the repeatable branch October 14, 2024 15:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants