You have to read the instructions with the foam. Mine states to leave at least one hour in gun. I use it but it's not the only step. I always continue the next day with other products.
For shotguns I 'set' the foam overnight then finish with bronze brush, hoppes or shooters Choice then a very light coat of Kyroil. If you put the gun in a safe, store it barrel down especially if it's going to 'rest' awhile before the next use. This allows any excess oil/solvent to run away from action and stock.
For rifles I use JB's boar paste(remove), a copper solvent like Sweets(remove), Hoppes or Shooters Choice(remove) then a very light coat of kyroil. Store upside.
My gunsmith swears by a product called Wipe Out which is a foam, they also sell an accelerator for this product.