Skip to content

Instantly share code, notes, and snippets.

@till-varoquaux
till-varoquaux / deferred.hpp
Created July 1, 2014 14:20
A small asynchronous monad...
#pragma once
/**
* This is a quick abstraction over non-blocking asynchronous deferreds. In a
* way you can see those as non-blocking futures (whereas std::future are
* blocking).
* This implementation is devoid of fanciness. Amongst other things:
* - Deferreds are not cancelable
* - They are not threadsafe. Callbacks are ran in whichever thread the
* deferred was triggered and there's no mutex to protect from race condition
* while registering callbacks/setting values. This is what we use libev