It's relatively straightforward. You put the code or whatever else your customers need into escrow with a third party. The code gets released if you discontinue the product or it otherwise leaves the market.
You then market that you're doing this, so that everyone A) knows they can pursue getting access to the escrowed stuff, B) it's a selling point to remove some of the vendor risk, and C) it's not just a capricious action to undermine creditor rights.
Of course, it may be harder to borrow money if you do this. And customers are generally not savvy enough to require this (though if you do a large enterprise deal, requiring code escrow is not an unknown term).