Skip to content

Pass promise returning disposer to Promise.using #429

Closed
@abresas

Description

@abresas

Right now, Promise.using accepts only Disposer instances but not promises that resolve to disposers.

For example in this code:

createTmp = function() {
    return tmp.fileAsync()
    .disposer( function( tmp ) {
        cleanup = tmp[2];
        cleanup();
    } );
};

createTmpDelayed = function() {
    return Promise.delay(1000)
    .then( function() {
        return createTmp();
    } );
};

passing createTmpDelayed() to Promise.using has a different outcome than passing createTmp().

This is not expected, as usually the bluebird API allows passing promises resolving to instances of a class, when the function expects a specific class. For example, .bind allows to pass promises that will be resolved to the object that will be binded.

Also, there is no way currently to write createTmpDelayed in such a way so as to transform the promise into a disposer.

createTmpDelayed = function() {
    return Promise.delay(1000)
    .then( function() {
        return createTmp();
    } ).dispose( function(disposer) {
        disposer.dispose(); // no such documented function
    } );
};

This makes it impossible to make generic functions that return Promises that resolve to disposers.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions