This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"github.com/golang/protobuf/proto" | |
"github.com/lightstep/lightstep-tracer-go/collectorpb" | |
"io/ioutil" | |
"log" | |
"net/http" | |
"os" | |
"time" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
include <set> | |
#include <assert.h> | |
template<typename Unutterable> | |
struct Board | |
{ | |
int length; | |
int height; | |
struct Coordinate |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace hask { | |
struct Unit { }; | |
template<typename S> | |
struct Stateful { | |
template<typename V> | |
struct Value | |
{ | |
std::function<std::pair<S,V>(S)> runState; | |
}; | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct counter : resource { int c; } r; | |
counter r2; | |
std::function<bool(int&)> is7 = [](int& x) -> bool { return x == 7; }; | |
r2.with_do([&]() { | |
if( r2.c != 7 ) | |
{ | |
std::cout << "Waiting for c to become 7.\n"; | |
} | |
r.await(std::bind(is7, std::ref(r2.c))); // r != r2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void await(std::function<bool()> cond) | |
{ | |
with_when_do(cond, []() { }); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
r.await( [&r]() { return r.c != 0; }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class resource { | |
recursive_mutex m_; | |
condition_variable cv_; | |
public: | |
resource() {} | |
void with_do(std::function<void()> body) | |
{ | |
m_.lock(); | |
at_scope_exit u( [&]() { cv_.notify_all(); m_.unlock(); } ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class resource { | |
recursive_mutex m_; | |
condition_variable cv_; | |
public: | |
resource() {} | |
void with_do(std::function<void()> body) | |
{ | |
m_.lock(); | |
at_scope_exit u( [&]() { cv_.notify_all(); m_.unlock(); } ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
auto incr = [&]() { r.c += 1; }; | |
r.with_do([&]() | |
{ | |
r.c += 1; | |
r.with_do(incr); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
r.with_do([&]() | |
{ | |
r.c += 1; | |
counter& shadow = r; | |
r.with_do([&]() { shadow.c += 1; }); | |
}); |
NewerOlder