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

Feature request: Allow binding methods without a promise. #4180

Closed
pdenapo opened this issue Mar 31, 2025 · 2 comments
Closed

Feature request: Allow binding methods without a promise. #4180

pdenapo opened this issue Mar 31, 2025 · 2 comments
Labels
Enhancement New feature or request

Comments

@pdenapo
Copy link

pdenapo commented Mar 31, 2025

Is your feature request related to a problem? Please describe.

It would be nice if wails could optionally generate bindings for go functions that do not return a promise (when no asynchronous operation is performed).

For instance, I have a Go function that converts a number in milliseconds to a string representing a date at my location [The reason why I don't want to do this in JavaScript is that they seem not to be compatible in doing this operation]. I want to call it from the JavaScript code. But this function does not involve any asynchronous
operation like reading from a database, etc. So there in no need of returning a Promise. And doing so, only increases complexity of the JavaScript code and overhead.

Describe the solution you'd like

It would be nice to have something like

// @nopromise
func (a* App) convert_to_date_string( mili int 64) string

The package

https://github.com/MarcGrol/golangAnnotations

might help.

Describe alternatives you've considered

No response

Additional context

No response

@pdenapo pdenapo added the Enhancement New feature or request label Mar 31, 2025
@symball
Copy link

symball commented Apr 8, 2025

The calls to the backend have to be asynchronous regardless of what the binding is doing.

The visual layer and Go code are effectively two different programs. There is the website SPA and a backend API (your bindings).

May i please suggest if you don't want to handle promises with YourMethod.then((result) => { ..do stuff with result... }, (error) => { ...do stuff with error... } ) you access the bindings in an async call. e.g.

const onClick = async () => {
    const result = await YourMethod()
}

this does mean you need to create some try / catch code to deal with the error however

const onClick = async () => {
    try {
        const result = await YourMethod()
        ...do stuff with the result...
   } catch (error) {
       ...do stuff with the error...
   }
}

@leaanthony
Copy link
Member

Synchronous calls aren't possible due to the underlying technology. I'd use await and if you use it in multiple places then create a sync function that deals with the promise.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants