Bitcoin Transaction Speed
Payment channels are a way to prevent double spending in such cases. As per the Wiki


  A Micropayment Channel or Payment Channel is class of techniques designed to allow users to make multiple Bitcoin transactions without commiting all of the transactions to the Bitcoin block chain.[1] In a typical payment channel, only two transactions are added to the block chain but an unlimited or nearly unlimted number of payments can be made between the participants. 


A possible way for implementing vending machines would involve creating payment channels beforehand with the vending machine company. 

Infact, for the vending machine case, an unidirectional channel would suffice. Refer to Wiki for details. Bi-directional payment channels using hashlocks are the key to Lightning network which is used to facilitate off-chain transactions at real-time.