Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clarify that components' invoke_...() calls through synchronously. #6457

Merged
merged 1 commit into from
Oct 7, 2024

Conversation

Enyium
Copy link
Contributor

@Enyium Enyium commented Oct 6, 2024

This makes it clear that you can expect that the Slint code isn't called in the next event loop run or so, but immediately.

Is this factual?

@@ -83,7 +83,7 @@ pub mod generated_code {
/// ```
pub fn on_hello(&self, f: impl Fn() + 'static) {}

/// For each public function declared at the root of the component, a function to call
/// For each public function declared at the root of the component, a function to synchronously call
Copy link
Member

Choose a reason for hiding this comment

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

I’m not sure this adds much value. I mean, this is a Rust function declaration, it returns a value, and it’s not declared async. How could it be interpreted as asynchronous?

I’m not opposed to the patch, but I’d like to better understand how this became unclear. Should this perhaps be documented elsewhere, in the general Slint docs? (It applies to all languages)

Copy link
Contributor Author

@Enyium Enyium Oct 6, 2024

Choose a reason for hiding this comment

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

It's functions to interface with the Slint context, which is kind of a dark pit without deeper knowledge. Okay, invoke_...() for function returns a value; but not invoke_...() for callback [in the sample component]. You could argue that something like changed-callbacks are also deferred. I just found myself in the situation of not trusting how exactly it behaves, when needing exact information to be able to prevent RefCell borrowing panics. And the docs didn't provide a guarantee in this regard. (See also #5885.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

But even regarding functions: I had function that takes a string and returns nothing. Because of that, I went directly to the docs text, ignoring the invoke_...() signature of the sample component, because I deemed it irrelevant and didn't think of other possible signatures.

Copy link
Member

Choose a reason for hiding this comment

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

it returns a value, and it’s not declared async. How could it be interpreted as asynchronous?

It doesn't always return a value and people wouldn't interpret it as async (rust term) but maybe as queued.

I think this clarification is accurate so I'll merge this patch. Thanks

@ogoffart ogoffart merged commit b3c9dfc into slint-ui:master Oct 7, 2024
36 checks passed
@Enyium Enyium deleted the patch-5 branch October 8, 2024 11:12
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.

3 participants