Skip to content

Callback on save? #6

@Lepozepo

Description

@Lepozepo

Hi! Any chance we could get a callback on the save function. I saw you wrote this using the fibers/future npm library.

_.extend(MeteorFile.prototype, {
  save: function (dirPath, options) {
    // should do dirPath checking here (see the next video or two in the series)
    var filepath = path.join(dirPath, this.name);
    var buffer = new Buffer(this.data);
    var future = new Future;

    // the future has a method named resolver that acts like a callback function that works with fibers
    fs.writeFile(filepath, buffer, options, future.resolver());

    // block the current fiber only (not the rest of the event loop)
    return future.wait();
  }
});

But I don't understand how to use it, lol.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions