Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Return promises instead of nesting them #407

Copy link
Copy link
@adius

Description

@adius
Issue body actions

The first example on the documentation reproduces callback hell which promises actually are supposed to prevent =D.

Instead of:

var clone = require("nodegit").Clone.clone;

// Clone a given repository into a tmp folder.
clone("git://github.com/nodegit/nodegit", "tmp").then(function(repo) {
  // Use a known commit sha from this repository.
  var sha = "59b20b8d5c6ff8d09518454d4dd8b7b30f095ab5";

  // Look up this known commit.
  repo.getCommit(sha).then(function(commit) {
    // Look up a specific file within that commit.
    commit.getEntry("README.md").then(function(entry) {
      // Get the blob contents from the file.
      entry.getBlob().then(function(blob) {
        // Show the name, sha, and filesize in byes.
        console.log(entry.filename(), entry.sha(), blob.rawsize());

        // Show a spacer.
        console.log(Array(72).join("=") + "\n\n");

        // Show the entire file.
        console.log(String(blob));
      });
    });
  });
});

you should write

var clone = require("nodegit").Clone.clone;

// Clone a given repository into a tmp folder.
clone("git://github.com/nodegit/nodegit", "tmp")
    .then(function(repo) {
        // Use a known commit sha from this repository.
        var sha = "59b20b8d5c6ff8d09518454d4dd8b7b30f095ab5";

        // Look up this known commit.
        return repo.getCommit(sha)
    })
    .then(function(commit) {
        // Look up a specific file within that commit.
        return commit.getEntry("README.md")
    })
    .then(function(entry) {
        // Get the blob contents from the file.
        return entry.getBlob()
    })
    .then(function(blob) {
        // Show the name, sha, and filesize in byes.
        console.log(entry.filename(), entry.sha(), blob.rawsize());

        // Show a spacer.
        console.log(Array(72).join("=") + "\n\n");

        // Show the entire file.
        console.log(String(blob));
    });
Reactions are currently unavailable

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.