GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Promisify async wrapper by sam-github · Pull Request #688 · nodejs/node

Promisify async wrapper #688

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.

Sign up for GitHub

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

Closed
sam-github wants to merge 2 commits into nodejs:v1.x from sam-github:promisify-async-wrapper

Uh oh!

There was an error while loading. Please reload this page.

Closed

Promisify async wrapper #688

Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit Hold shift + click to select a range
230cf27
fs: C++ promisification of fs.stat
sam-github Jan 1, 2015
a6313a6
!benchmarks from io.js#173
sam-github Jan 9, 2015
File filter
Filter by extension

Clear filters
Conversations
Failed to load comments.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Jump to
Jump to file
Failed to load files.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Diff view
Diff view
Next Next commit
fs: C++ promisification of fs.stat
  • Loading branch information

Uh oh!

There was an error while loading. Please reload this page.

@sam-github
sam-github committed Jan 9, 2015
commit 230cf273b40255e30858e09dc51dddc484394910

There are no files selected for viewing

37 changes: 30 additions & 7 deletions 37 lib/fs.js
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,12 @@ function nullCheck(path, callback) {
var er = new Error('Path must be a string without null bytes.');
if (!callback)
throw er;
process.nextTick(function() {
callback(er);
});
if (callback.reject)
callback.reject(er);
else
process.nextTick(function() {
callback(er);
});
return false;
}
return true;
Expand Down Expand Up @@ -780,12 +783,32 @@ fs.lstat = function(path, callback) {
binding.lstat(pathModule._makeLong(path), req);
};

fs.stat = function(path, callback) {
callback = makeCallback(callback);
if (!nullCheck(path, callback)) return;
function makeOnComplete(cb) {
return function oncomplete() {
return cb.apply(null, arguments);
};
}

function Defer(callback) {
var req = new FSReqWrap();
req.oncomplete = callback;
if (util.isFunction(callback)) {
Comment thread Outdated

@brendanashworth brendanashworth Feb 13, 2015

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe switch to typeof callback === 'function'?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
req.oncomplete = makeOnComplete(callback);
// Below causes stat/test to reduce from >58K to < 50K, why?
// req.oncomplete = function() { return callback.apply(null, arguments); };
return req;
}
req.promise = new Promise(function(resolve, reject) {
req.resolve = resolve;
req.reject = reject;
});
return req;
}

fs.stat = function(path, callback) {
var req = Defer(callback);
if (!nullCheck(path, req)) return req.promise;
binding.stat(pathModule._makeLong(path), req);
return req.promise;
};

fs.fstatSync = function(fd) {
Expand Down
2 changes: 2 additions & 0 deletions 2 src/env.h
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,10 @@ namespace node {
V(received_shutdown_string, "receivedShutdown") \
V(refresh_string, "refresh") \
V(regexp_string, "regexp") \
V(reject_string, "reject") \
V(rename_string, "rename") \
V(replacement_string, "replacement") \
V(resolve_string, "resolve") \
V(retry_string, "retry") \
V(rss_string, "rss") \
V(serial_string, "serial") \
Expand Down
2 changes: 1 addition & 1 deletion 2 src/node_file.cc
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ static void After(uv_fs_t *req) {
}
}

req_wrap->MakeCallback(env->oncomplete_string(), argc, argv);
req_wrap->Fulfill(argc, argv);

uv_fs_req_cleanup(&req_wrap->req_);
delete req_wrap;
Expand Down
18 changes: 18 additions & 0 deletions 18 src/req_wrap.h
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,24 @@ class ReqWrap : public AsyncWrap {
persistent().Reset();
}

inline v8::Handle<v8::Value> Fulfill(int argc, v8::Handle<v8::Value>* argv) {
// if (obj.oncomplete) .oncomplete(argv)
v8::Local<v8::Value> cb_v = object()->Get(env()->oncomplete_string());
if (cb_v->IsFunction()) {
return MakeCallback(cb_v.As<v8::Function>(), argc, argv);
}
// else
// if (argv[0]) obj.reject(argv[0])
// else obj.resolve(argv[1...])
if (argc == 0)
return MakeCallback(env()->resolve_string(), 0, NULL);

if (argv[0]->ToBoolean()->IsTrue()) // if(err) {
return MakeCallback(env()->reject_string(), 1, argv);

return MakeCallback(env()->resolve_string(), argc-1, argv+1);
}

// Call this after the req has been dispatched.
void Dispatched() {
req_.data = this;
Expand Down
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.