std::function<void()> InstanceImpl::SlotImpl::wrapCallback(const std::function<void()>& cb) {
[index = index_, cb, &dispatcher]() -> void { setThreadLocal(index, cb(dispatcher)); }));
// threads have already shut down and the dispatcher is no longer alive. There is also no reason
new std::function<void()>(cb), [this, all_threads_complete_cb](std::function<void()>* cb) {
// more base layer things. The reason reverse ordering is done is to deal with the case that leaf
// objects depend in some way on "persistent" objects (particularly the cluster manager) that are
// created very early on with a known slot number and never destroyed until shutdown. For example,
// if we chose to create persistent per-thread gRPC clients we would potentially run into shutdown
// currently when a redis connection pool is destroyed and removes its member update callback from
// It's possible this might need to become more complicated later but it's OK for now. Note that
for (auto it = thread_local_data_.data_.rbegin(); it != thread_local_data_.data_.rend(); ++it) {