Skip to content

Any way to wrap spooky in a promise? #202

@jamesaspence

Description

@jamesaspence

I'm hoping to achieve something like this:

function createSpooky() {
    return new Promise(function (resolve) {
        var spooky = new Spooky(opts, function (err) {
            if (err) {
                var e = new Error('Failed');
                e.details = err;
                throw e;
            }

            resolve(spooky)
        });
    });
}

That way, I could do something like:

createSpooky().then(function (spooky) {
    spooky.open('https://google.com');
    //Initialize the rest of our spooky steps here!
});

Every time I try to resolve spooky via that promise, however, I get an error (kinda); Uncaught, unspecified "error" event. ([object Object]).

I'm not sure how to continue from here. Maybe this is my lack of understanding promises fully, or spooky's limitations, but is such a thing possible? Am I going about it completely wrong? I'm just hoping to avoid callback hell and I really like to chain my thens (i.e. createSpooky().then(doStuff).then(doMoreStuff)

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