Skip to content

Instantly share code, notes, and snippets.

@lonsdale8734
lonsdale8734 / async.js
Last active October 16, 2020 14:12
async await simulated with generator
function AsyncRun(generatorCreator) {
const generator = generatorCreator();
function handleNext(next) {
if (next.done) {
// return Promise.resolve(next.value);
return next.value;
} else {
return next.value.then(handleSuccess, handleError);
}
@lonsdale8734
lonsdale8734 / cpp
Last active October 12, 2020 12:13
static range loop for c++ template. Idea from http://spraetor.github.io/2015/12/26/compile-time-loops.html
#include <type_traits>
#include <utility>
namespace detail
{
constexpr inline int Sgn(int v)
{
return (v > 0) - (v < 0);
}