Skip to content

Commit 7a19754

Browse files
committed
Couldn't sleep until I made OpenAfterWork call its callback with error, object like *all* the other async methods.
1 parent 34306bf commit 7a19754

2 files changed

Lines changed: 22 additions & 9 deletions

File tree

lib/repo.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,12 @@ exports.repo = function(directory, callback) {
1313
if (!callback || typeof callback !== 'function') {
1414
throw new Error('If directory is provided, callback function is required');
1515
}
16-
self.repo.open(directory, function(error) {
16+
self.repo.open(directory, function(error, rawRepo) {
1717
if (error) {
1818
callback(git.error(error), null);
1919
return;
2020
}
21+
self.repo = rawRepo;
2122
callback(null, self);
2223
});
2324
}

src/repo.cc

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -95,22 +95,34 @@ void GitRepo::OpenAfterWork(uv_work_t *req) {
9595
OpenBaton *baton = static_cast<OpenBaton *>(req->data);
9696
delete req;
9797

98-
baton->repo->SetValue(baton->rawRepo);
9998
baton->repo->Unref();
10099

101-
Local<Value> argv[1];
102100
if (baton->error) {
103-
argv[0] = GitError::WrapError(baton->error);
101+
Local<Value> argv[1] = {
102+
GitError::WrapError(baton->error)
103+
};
104+
105+
TryCatch try_catch;
106+
107+
baton->callback->Call(Context::GetCurrent()->Global(), 1, argv);
108+
109+
if (try_catch.HasCaught()) {
110+
node::FatalException(try_catch);
111+
}
104112
} else {
105-
argv[0] = Local<Value>::New(Null());
106-
}
107113

108-
TryCatch try_catch;
114+
baton->repo->SetValue(baton->rawRepo);
109115

110-
baton->callback->Call(Context::GetCurrent()->Global(), 1, argv);
116+
Handle<Value> argv[2] = {
117+
Local<Value>::New(Null()),
118+
baton->repo->handle_
119+
};
111120

112-
if (try_catch.HasCaught()) {
121+
TryCatch try_catch;
122+
baton->callback->Call(Context::GetCurrent()->Global(), 2, argv);
123+
if (try_catch.HasCaught()) {
113124
node::FatalException(try_catch);
125+
}
114126
}
115127
}
116128

0 commit comments

Comments
 (0)