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

Add method to wrap functions (promiserize) #3

Open
amatiasq opened this issue Apr 3, 2013 · 0 comments
Open

Add method to wrap functions (promiserize) #3

amatiasq opened this issue Apr 3, 2013 · 0 comments
Assignees
Milestone

Comments

@amatiasq
Copy link
Owner

amatiasq commented Apr 3, 2013

We need a function to wrap any function so the execution is deferred until all promise-arguments are fulfilled. So this code

getNumber(function(num) {
    var result = Math.pow(num);
    heavyCheck(result, function(isValid) {
        console.log("Valid:", isValid);
    });
});

Can be written like this:

heavyCheck = promiserize(heavyCheck);
console.log = promiserize(console.log);

var result = getNumber();
var isValid = heavyCheck(result);
console.log(isValid);

result is a promise
isValid is a promise
heavyCheck will wait until result is fulfilled then will perfom it's async operation and will return a promise
isValid will be binded to this promise so when the returned promise is resolved or rejected isValid will be too.
console.log will wait until isValid is fulfilled

@ghost ghost assigned amatiasq Apr 3, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant