question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Can't get promisify working with a basic example

See original GitHub issue

I’m really hoping that I’ve just continually missed something obvious here, but after trying for hours to use promisify, I’ve distilled things down to a VERY simple example that only logs “running” and never “then”. What have I missed or is this a bug?

<html>
    <head>
        <script src="http://requirejs.org/docs/release/2.1.2/minified/require.js"></script>
    </head>

    <body>

        <script>

            require(['https://cdnjs.cloudflare.com/ajax/libs/bluebird/2.10.1/bluebird.js'], function( Promise ) {

                var initServer = Promise.promisify( function( foobar ) {
                    console.log( 'running' );
                    return  true;
                } )( { foobar: 1 } ).then( function( ) {
                    console.log( 'then' );
                });

            });

        </script>

    </body>
</html>

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:5

github_iconTop GitHub Comments

3reactions
rainabbacommented, Sep 23, 2015

haha. That fs example is why I’ve not understood sooner. Not ONE example out there is standalone (and thus clear). Thank you though, I did figure it out and am leaving it here for anyone else that might find it useful:

Here is a Gist that covers both approaches with errors: https://gist.github.com/rainabba/b83eed7f6317e5e7d945

0reactions
phpnodecommented, Sep 23, 2015

for illustration purposes, don’t actually do this, use .promisifyAll() instead

const fs = require("fs");
const stat = Bluebird.promisify(fs.stat);

stat(__filename).then(console.log);
Read more comments on GitHub >

github_iconTop Results From Across the Web

I'm trying to use the Bluebird's method Promisify and it's not ...
Bluebird's promisify () only works with node-style functions that take a callback as their last argument where that callback takes two ...
Read more >
Promisification - The Modern JavaScript Tutorial
“Promisification” is a long word for a simple transformation. It's the conversion of a function that accepts a callback into a function that ......
Read more >
Node.js util.promisify() Method - GeeksforGeeks
The util.promisify() method defines in utilities module of Node.js standard library. It is basically used to convert a method that returns ...
Read more >
Resolving the JavaScript Promise Error "TypeError: Cannot ...
Working with JavaScript Promise comes with its own array of errors, and a popular one is TypeError: Cannot read property 'then' of undefined ......
Read more >
JavaScript Promise Tutorial – How to Resolve or Reject ...
A rejected promise is returned for any kind of errors. We will be using this function in several examples from now on to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found