Skip to content

[Request for comment] Support for Promises #155

Closed
@ncanumalla-splunk

Description

@ncanumalla-splunk

In response to the feedback about inconveniences caused by callbacks in the SDK ( #81 ) and our continued efforts to improve the developer experience, we are planning to introduce Promises in the next release of the Javascript SDK.
These changes will be backwards incompatible. Therefore, we would love your feedback and validation of these major changes before we release them.

Description of changes

We have added support for Promises to some methods, and replaced the abort() method with the response_timeout argument which you can pass during a method call to specify a timeout for aborting a request.

Existing Callback Approach:

var appName = "<app-name>";
service.apps().fetch(function (err, apps) {
    if (err)
        console.log("There was an error retrieving the list of applications:", err);
    else{
        var app = apps.item(appName);
        app.fetch(function (err, app) {
            if (err)
                console.log("Can't fetch an app, Error : ", err);
            else{
                console.log("App author name - ", app._author);
            }
        });
    }
});

Proposed Promise Approach:

var appName = "<app-name>";  
try {
        var apps = service.apps();
        await apps.fetch();
        
        var app = apps.item(appName);
        await app.fetch();
        console.log("App author name - ", app._author);
    } catch (error) {
        console.log("Error :", error);
    }

Refer to this branch with the changes for more details - GitHub - splunk/splunk-sdk-javascript at callback-to-promises-changes.

Feedback requested

We would love for you to try out these changes and let us know your feedback.
Here is an example file you can use to test the changes- promise-example.js. Make sure to replace token value with the bearer_token/session_key before execution.

  • Please indicate with an upvote or downvote on this issue if you would like to see the support for Promises in the SDK.
  • Please post your feedback and suggestions on these changes as comments below.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions