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

Upgrade APIs to return Javascript Promises. #10

Open
Giwayume opened this issue Apr 7, 2020 · 1 comment
Open

Upgrade APIs to return Javascript Promises. #10

Giwayume opened this issue Apr 7, 2020 · 1 comment

Comments

@Giwayume
Copy link

Giwayume commented Apr 7, 2020

Since async functions have been introduced to Javascript, I find it difficult to use libraries that resort to passing callback functions as arguments, as callbacks are an inferior syntax that cause stacking, and await introduces performance optimizations for Javascript engines.

I suggest if a callback function is not passed into any of the API calls, return a promise that resolve or rejects with the result. This way, the API is being expanded and doesn't introduce any breaking changes.

e.g.

async function runMySearch() {
    try {
        const res = await client.search({
            engine: "my-engine",
            q: "cats",
            filters: {
                page: {
                    enumField: "theFilter"
                }
            },
            facets: {
                page: ["enumField", "anotherField"]
            }
        });
        console.log(res);
    } catch(err) {
        console.log(err);
    }
}
@JasonStoltz
Copy link
Member

This is a great suggestion, thank you.

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

No branches or pull requests

2 participants