-
Notifications
You must be signed in to change notification settings - Fork 14
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
Align Semantics with Zone.js #9
Comments
That's not a question :). Shared resources are not super common but sometimes they are inevitable. Some examples:
Arbitrarily attaching metadata to an object that has class methods of its own is dangerous and makes it difficult to expand the API in the future. Node suffers from this problem. The "mongoose" library (ORM for MongoDB) has decided that any additional properties that are added to an EventEmitter are treated as fields that can be inserted in the database. Therefore we couldn't for example add Creating nested/child zones
|
|
@piscisaureus – thanks for the writeup! I'll incorporate this into my original post when I get a moment. @sam-github thanks for the feedback. I'm not married to |
I've updated my OP. I think the biggest thing to resolve is the difference between target use cases as described in the summary. |
That's correct
That's correct too. I'm not sure it's super necessary although I don't mind giving it a thought. However I like to keep in mind use cases when designing a library like this. What is the purpose of overwriting e.g. setTimeout(). Also node has a plethora of asynchronous functions which are not exposed on the global object, and people can implement their own in libraries. So tacking everying on the zone object seems a little unpractical, e.g. where would 'require('stream').Stream.prototype.write(buffer, cb)` go? "After" tasks are available via |
Yeah, agreed. I don't think being able to patch every function makes sense. But I don't want it to be too cumbersome to patch things like |
I think what we're discovering is that we are not solving exactly the same problem. At least, I am discovering it - you potentially already knew :) Indeed what we are trying to do is come up with a concept that manages async "things" and resources and handles errors in a reasonable way. To do that we (as in the zone implementers) are monkey-patching all node APIs so their callbacks run in the correct zone and general behavior in a zone context is reasonable. You are trying to create a lightweight execution context that makes it possible for the user to instrument/hook particular functions. In node people typically do this with contextify, which creates a new v8 context with a user-specified global object. So for our use case it is important that zones have a natural end to them so they don't leak and, more importantly, resources attached to a zone don't leak. What you need is a way to hook any function, which I can imagine is possible in the browser but really hard on the server. What we both need is a way to maintain an asynchronous context. So what we could do is limit the scope of this discussion for now, and only specify the things that are needed for both our use cases. Things that come to mind:
I can even imagine that I rename the core concept of Zone to something else (e.g. "Task" - what you have called "counting zone"), which is basically a superset of a Zone. A non-counting Zone would have valid use cases in a node context too. |
Based on our discussion in person yesterday, I think we are pretty close to being compatible now. zone.js looks like it offers a subset for functionality in the zone library. Looking at the original use cases:
I split this out into #16 so we can discuss it there in more detail
This would be the zone.then(...) function. This also implies that zones have a fixed lifetime and are alive as long as there is something to do within them or they are expecting an event to happen (I/O, timeout, EventEmitter/listener) |
This is a WIP; I'm still digesting the docs in this repo.
Background
I'm working on a distinct ES5 implementation of zones for browsers.
It would be nice if the semantics for both libraries are similar.
It also might be good to develop a spec so that someday JS knows how to do this without monkeypatching the universe.
This is written mostly for @piscisaureus to begin discussing the differences in our libraries.
Summary
Conceptually, there are two broad classes of uses for zones:
Zone.js
Zone.js is concerned with exposing a minimal set of hooks and the ability to compose behaviors.
Zone.js has a number of optional "zones" built on top of it to provide functionality some of
the same functionality as
zone
:Counting Zone:
zone
zone
seems concerned with solving control-flow problems, resource management, and cleanup.It doesn't seem like
zone
has hooks for before/after tasks or for overriding functionality.Zones
zone
hasZone.data
Creating nested/child zones
fork
.Gates
The text was updated successfully, but these errors were encountered: