The maze book for programmers!
mazesforprogrammers.com

Algorithms, circle mazes, hex grids, masking, weaving, braiding, 3D and 4D grids, spheres, and more!

DRM-Free Ebook

The Buckblog

assorted ramblings by Jamis Buck

Reloading Dependencies

10 October 2004 — 1-minute read

Leon Breedt recently proposed a way to allow services to be refreshed automatically when their dependencies are altered, in Syringe (ruby-talk:116021, among others). Although I don’t think his proposed solution is generally possible in Syringe, it did inspire me with another idea.

My response to his post (ruby-talk:116040) described a new service model, whimsically termed RefreshableServiceModel, that would allow services to be registered and manually identified as observers on other services. It wraps its services in a kind of deferring proxy. When the observed services emit an explicit “refresh!” signal, the observers then reload themselves and cause their wrapped services to be reinstantiated.

To properly support what Leon mentioned, this would require that upon recieving a “refresh!” notification, each service should also emit its own “refresh!” notification, after reloading itself. This will propogate the refresh all the way through the dependency graph. However, since cycles in the graph are possible, this means that some way of detecting the cycles and preventing an infinite loop would be necessary, too.

I haven’t tried implementing it yet, so I don’t know if it will work, but I’m tempted… I’m still a little doubtful about how generally useful this would be, though.