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

Pass promise returning disposer to Promise.using #429

Closed
abresas opened this issue Jan 9, 2015 · 1 comment
Closed

Pass promise returning disposer to Promise.using #429

abresas opened this issue Jan 9, 2015 · 1 comment

Comments

@abresas
Copy link

abresas commented Jan 9, 2015

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.

@abresas
Copy link
Author

abresas commented Jan 10, 2015

You are awesome! Thanks for quick fix!

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

1 participant