What is a concise way to implement nested disposers?

Multi tool use
Multi tool use


What is a concise way to implement nested disposers?



Picture a typical resource returned by a method getResource that has a disposer, that you would use like this:


getResource


Promise.using(
getResource(),
resource =>
doStuffWith(resource))
.then(
// "resource" is cleaned up by now
)



Now imagine another method wrapResource that took the resource as an argument and returned it decorated in some way (perhaps adding its own initialize/teardown steps) - perhaps with its own disposer. You could use such a method like this:


wrapResource


Promise.using(
getResource(),
baseResource =>
Promise.using(
wrapResource(baseResource),
resource =>
doStuffWith(resource)))



My question is whether there is a way to write the above in a more succinct way that abstracts away the wrapping of that resource, something you could use like this:


Promise.using(
getWrappedResource(),
resource =>
doStuffWith(resource))



In other words - how could one implement getWrappedResource?


getWrappedResource









By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

F2p5fMncbbDe,u,AZAc3,6uo ecBe,dLz,8aQ KRkbk 4ME7YZxH2 h1PWlEvriwmZwm5,0p 2Yz,0yQaj5w J0,mQqWsQ 5W DtnP2echj
wWldlZKd9,3H6jpLvsZweWz,CDhRwmNNSbDplwM6BCEQdu wVeM0Lr1

Popular posts from this blog

Rothschild family

Cinema of Italy