Skip to content

[WIP] Add first-class stateful iterator to Cron class#97

Closed
Copilot wants to merge 1 commit intomainfrom
copilot/add-cron-stateful-iterator
Closed

[WIP] Add first-class stateful iterator to Cron class#97
Copilot wants to merge 1 commit intomainfrom
copilot/add-cron-stateful-iterator

Conversation

Copy link
Contributor

Copilot AI commented Mar 5, 2026

Thanks for asking me to work on this. I will get started on it and keep this PR's description up to date as I form a plan and make progress.

Add a first-class, ECMAScript-compliant stateful iterator to the Cron class to allow sequential date traversal without breaking the existing stateless API.
​Technical Requirements:
​Factory Method: Add Cron.prototype.enumerate(startAt?) to the main class. It should return a new CronIterator instance.
​CronIterator Class: * Maintain an internal cursor initialized to startAt or Date.now().
​Implement the Iterator Protocol: .next() must return { value: Date, done: boolean }.
​Implement the Iterable Protocol: Symbol.iterator { return this; } to enable for...of loops and destructuring.
​Logic: Each .next() call should advance the cursor using the parent Cron instance’s next(this.cursor) logic.
​Boundary Handling: If the schedule reaches a defined stopAt or the end of a sequence, return done: true.
​Utility Methods:
​.peek(): Return the next date without advancing the cursor.
​.reset(newStartAt?): Reset the internal cursor.
​Success Criteria:
​for (const date of job.enumerate()) works natively.
​const [a, b] = job.enumerate() correctly captures the next two occurrences.
​The core Cron class remains stateless (calling enumerate does not change the behavior of the base instance).


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot stopped work on behalf of Hexagon due to an error March 5, 2026 22:51
@Hexagon Hexagon closed this Mar 5, 2026
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