# coroutines

Allan Wang

12/26/2018, 4:57 AM
I want to make a flyweight using coroutines, where requests pass in a key and take in a value. If the value has already been requested within some amount of time, I want to reuse it, and if multiple requests are made with the same key, I only want the value to be fetched once and used for all requests. (This is very similar to this:

). Anyone should also be able to invalidate a current value, so that it is fetched again by future requests. I wrote a mock up here, but I’m wondering a few things: • Is it okay to wrap all of the channels in a single
? That is one of the differences here compared to the example in the video • Is the usage of
within the main
method acceptable? It is there purely to send an event to a channel while allowing me to use the coroutine continuation • Is it acceptable that all the maps are global. In the example, they are all within the
code. I’m not sure if this affect access from a different thread or not.


12/26/2018, 1:31 PM
I kinda forgot what a flyweight is For a start though I think that code shouldn't be in an init block