Skip to content

refactor!: Major code cleanup for clearer state - #27

Merged
JR-Morgan merged 25 commits into
devfrom
jrm/sourcelink
Jun 16, 2025
Merged

refactor!: Major code cleanup for clearer state#27
JR-Morgan merged 25 commits into
devfrom
jrm/sourcelink

Conversation

@JR-Morgan

@JR-Morgan JR-Morgan commented Jun 12, 2025

Copy link
Copy Markdown
Member

Major refactor

Code cleanup, I've tried to make the state handling clearer by wrapping the worker state in a new Worker class.
Cleaner code around reset of state
More proper disposal logic (still not perfect)
Breaking change around DoWork function now returns a Task object.

Non-async function should simply return a Task.CompletedTask
async functions can now await

TODO: check with Adam, we may actually prefer using an async void pattern here. The root task isn't awaited, so it's not like we need to keep the await chain... but it feels weird to have a Task that wraps an async void

@JR-Morgan
JR-Morgan marked this pull request as draft June 12, 2025 13:33
@JR-Morgan
JR-Morgan changed the base branch from main to jrm/confirmed-working June 13, 2025 16:00
@JR-Morgan
JR-Morgan changed the base branch from jrm/confirmed-working to dev June 13, 2025 16:21
@JR-Morgan JR-Morgan changed the title Add Source link and minor refactor for nullability syntax + prop naming refactor: Major refactor for better async, and code cleanup for clearer state Jun 13, 2025
@JR-Morgan JR-Morgan changed the title refactor: Major refactor for better async, and code cleanup for clearer state refactor: Major code cleanup for clearer state Jun 13, 2025
@JR-Morgan JR-Morgan changed the title refactor: Major code cleanup for clearer state refactor!: Major code cleanup for clearer state Jun 13, 2025
@JR-Morgan
JR-Morgan marked this pull request as ready for review June 13, 2025 18:38
@JR-Morgan
JR-Morgan requested a review from adamhathcock June 13, 2025 18:39
(TaskCreationOptions)TaskCreationOptions
)
: new Task(() => currentWorker.DoWork(_reportProgress, _done), tokenSource.Token);
var currentRun = new Task<Task>(

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Task.Factory.StartNew()

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No try/catch or other error handling for this task? Unobserved task exceptions 😬

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's important that the tasks don't start within this SolveInstance.
They get started all together in PostSolveInstance

That way, it it guaranteed that a task never calls Done while we are still spinning up workers. That would break the components state tracking.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps there's alternatives with storing Func<Task>, but for this PR I wanted to keep minimal changes

@adamhathcock adamhathcock left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We probably want some basic error handling and feed back. I don't think we should be delegating this to the caller, at least for cancellation exceptions.

Good clean up though, much nicer.

(TaskCreationOptions)TaskCreationOptions
)
: new Task(() => currentWorker.DoWork(_reportProgress, _done), tokenSource.Token);
var currentRun = new Task<Task>(

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No try/catch or other error handling for this task? Unobserved task exceptions 😬

@JR-Morgan

Copy link
Copy Markdown
Member Author

No error handling, because this component cannot really handle the errors.
Not ideal, I would really like to refactor a bit how cancellation is handled. But to keep these changes minimal, I've not changed the current pattern

@JR-Morgan
JR-Morgan merged commit a50809b into dev Jun 16, 2025
@JR-Morgan
JR-Morgan deleted the jrm/sourcelink branch June 16, 2025 12:00
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