Hi,
I was wondering if anyone had any concrete thoughts about what should happen with IResource.getChild being able to return Deferreds, or, in general, the ability to asynchronously get children of a resource. The ticket for this is #3621.
My use case for this is txYoga. Long story short, it lets you write REST-y webapps. So, you could have something like:
http://www.twistedmatrix.com/labs/glyph
In local jargon, labs is a collection, and glyph is an element in it. Right now, the only collection that actually exists is an in-memory one, and the next one I'm going to write is a SQLite one, so blocking on child access seems relatively reasonable. In general, however, this should be implemented using Deferreds, since the information about glyph might be stored in a database far, far away.
The logical way to do that for me seems to be that in getChild, you'd
I have found a mailing list post (from 2002) where Christopher Armstrong ostensibly solved the problem. I can't find any replies to that mailing list post.
I remember Glyph saying something about how that could potentially change/break public API. I understand that reservation, but I don't see how it'd be that bad. Existing code that always immediately returns a resource would still work -- it would merely only use a part of the API it's allowed to use (in this case, it'd ignore the fact that it is allowed to return a deferred). Since a Deferred isn't an IResource, it wouldn't be a legal value to return now, anyway.
Obviously, code that previously relied on getChild always returning a child *right now*, when now that getChild will occasionally return a deferred, would break. I'm not sure yet if that's a serious problem, or just a breach of the contract that code previously had. I'm thinking it's the latter, but maybe my subconscious is cheating to get to the easier answer.
I don't actually call getChild myself in my application code. I call it in tests, and Twisted calls it for me in production. Maybe I'm missing major use cases for getChild there? I could definitely see how that works.
Thoughts welcome :)
cheers