Check programmatically whether the current request is asynchronous (AJAX)

Magento 1.x code:

Mage::app()->getRequest()->isXmlHttpRequest()

Magento 2 code:

/** @return bool */
function rm_is_ajax() {
	/** @var \Magento\Framework\ObjectManagerInterface $om */
	$om = \Magento\Framework\App\ObjectManager::getInstance();
	/** @var \Magento\Framework\App\RequestInterface|\Magento\Framework\App\Request\Http $request */
	$request = $om->get('Magento\Framework\App\RequestInterface');
	return $request->isXmlHttpRequest();
}