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

feat: promise with callback plugin method #5622

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

matthiasschwarz
Copy link

Description

Fixes #5618
Allows to add a callback function to a plugin method which returns a promise. Calling call.resolve() on keep alive passes the object to the callback - when a callback was provided. Setting keep alive to false passes the object to the promise and resolves it. call.reject() rejects the promise and deletes the saved callback.

This should not be a breaking change to the value return method type when no callback function is provided to the method or keep alive is never set to true.

Android example usage

@CapacitorPlugin(name = "Example")
public class ExamplePlugin extends Plugin {
    @PluginMethod()
    public void example(PluginCall call) {
        String v = call.getString("v");
        call.setKeepAlive(true);
        call.resolve(new JSObject().put("n", 1));
        call.resolve(new JSObject().put("n", 2));
        call.resolve(new JSObject().put("n", 3));
        call.setKeepAlive(false);
        call.resolve(new JSObject().put("i", 42).put("r", v));
    }
}

Platform(s)

  • Android
  • iOS (untested)

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.

feat: plugin method with callback and custom return type
1 participant