Skip to content
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.

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

Decouple callback wrapping from registration #38

Open
piscisaureus opened this issue Nov 4, 2014 · 0 comments
Open

Decouple callback wrapping from registration #38

piscisaureus opened this issue Nov 4, 2014 · 0 comments
Assignees

Comments

@piscisaureus
Copy link
Contributor

Right now, making an asynchronous function that takes a callback zone-aware more or less looks like the following.

// Pseudo code
function wrappedAsyncFunc(arg1, arg2, cb) {
  cb = zone.registerCallback(cb);
  try {
    return asyncFunc(arg1, arg2, cb);
  } catch (e) {
    zone.unregisterCallback(cb);
    throw e;
  }
}

I would like to ditch the try-catch block. That's more performant and also more straightforward. We can get there by decoupling wrapping from registration with the target zone. Like this:

// Pseudo code
function wrappedAsyncFunc(arg1, arg2, cb) {
  cb = zone.createCallback(cb);
  var r = asyncFunc(arg1, arg2, cb);
  zone.registerCallback(cb);
  return r;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants