Skip to content

Conversation

@typester
Copy link
Contributor

@typester typester commented Mar 3, 2025

Panic occurring in Promise::try_result is undesirable, so it has been replaced with RwLock to prevent panics.

@ilo-nanpa
Copy link
Contributor

ilo-nanpa bot commented Mar 3, 2025

it seems like you haven't added any nanpa changeset files to this PR.

if this pull request includes changes to code, make sure to add a changeset, by writing a file to .nanpa/<unique-name>.kdl:

minor type="added" "Introduce frobnication algorithm"

refer to the manpage for more information.

@typester typester requested review from bcherry and theomonnom March 3, 2025 22:58

pub fn try_result(&self) -> Option<T> {
self.result.try_lock().unwrap().clone()
self.result.try_read().unwrap().clone()
Copy link
Member

Choose a reason for hiding this comment

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

isn't try_read also panicking? when unwrapping?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, good catch! Thank you. I believe a panic would occur if a write lock is held.

So in this case, I'll modify it to return None instead of unwrapping. Since Promise is designed to acquire the write lock only once, this should not be an issue.

@typester typester merged commit 3e51cda into main Mar 3, 2025
9 checks passed
@typester typester deleted the typester/promise-race-condition branch March 3, 2025 23:49
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.

4 participants