Hi,<br><br><br>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 <a href="http://tm.tl/3621">#3621</a>.<br>
<br>My use case for this is <a href="https://github.com/lvh/txyoga">txYoga</a>. Long story short, it lets you write REST-y webapps. So, you could have something like:<br><br><a href="http://www.twistedmatrix.com/labs/glyph">http://www.twistedmatrix.com/labs/glyph</a><br>
<br>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.<br>
<br>The logical way to do that for me seems to be that in getChild, you'd <br><br>I have found a <a href="http://www.twistedmatrix.com/pipermail/twisted-python/2002-October/001847.html">mailing list post</a> (from 2002) where Christopher Armstrong ostensibly solved the problem. I can't find any replies to that mailing list post.<br>
<br>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.<br>
<br>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.<br>
<br>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.<br>
<br>Thoughts welcome :)<br><br><br>cheers<div>lvh</div><br>