Chef John's Mushroom Gravy

1/4 cup butter
1 (16 ounce) package sliced mushrooms
salt to taste
1/4 cup all-purpose flour, or as needed
1 quart beef stock
1 pinch ground black pepper to taste
fresh thyme leaves, to taste (optional)

Heat butter over medium heat in a saucepan until it foams. Stir in mushrooms. Season with salt. Simmer until liquid evaporates, about 20 minutes.
Stir in the flour, cooking and stirring for about 5 minutes. Add about 1 cup of beef stock, stirring briskly until incorporated, then pour in the remaining stock and mix thoroughly. Season with black pepper and thyme. Reduce heat to medium-low, and simmer until thickened, about 30 minutes, stirring often.