Git Product home page Git Product logo

Comments (6)

tomasdev avatar tomasdev commented on August 17, 2024 1

Pull request added, candidate docs in PR can be previewed at https://github.com/tomasdev/instagram-node/#promises

from instagram-node.

limafelipe avatar limafelipe commented on August 17, 2024

+1

from instagram-node.

mwhitlock avatar mwhitlock commented on August 17, 2024

+1

from instagram-node.

pamo avatar pamo commented on August 17, 2024

How's this coming along?

from instagram-node.

tomasdev avatar tomasdev commented on August 17, 2024

@pamo not coming. Would you like to do it? go for it!, btw repo owner never replied...

from instagram-node.

tomasdev avatar tomasdev commented on August 17, 2024

In case you still need it, this is a workaround to "promisify" this module API. Sample usage included:

var promisedAPI = {};

Object.keys(api).forEach(function (key) {
    promisedAPI[key] = function () {
        var context = this,
            args = Array.prototype.slice.call(arguments);

        return new Promise(function (fulfill, reject) {
            args.push(function (err) {
                if (err) {
                    reject(err);
                } else {
                    Array.prototype.shift.call(arguments);
                    fulfill.apply(null, arguments);
                }
            });

            api[key].apply(null, args);
        });
    }
});

// Sample usage based on the demo express app from README file
app.get('/', function (req, res) {
    // BEFORE:
    // api.user_media_recent('30739527', function (err, result) {
    //     res.send(JSON.stringify(result));
    // });

    // AFTER:
    promisedAPI.user_media_recent('30739527').then(JSON.stringify).then(res.send.bind(res));
});

I think there's no way of making it backwards compatible with the current non-promises approach and also I haven't heard from @totemstech on this thread either.

from instagram-node.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.