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:
https://www.youtube.com/watch?v=a3agLJQ6vt8▾
). 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
select
? That is one of the differences here compared to the example in the video
• Is the usage of
launch
within the main
fetch
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
launch
code. I’m not sure if this affect access from a different thread or not.