View action.js
export function handleAction (action) { | |
const args = action.payload || [] | |
switch (action.type) { | |
case DO_SOMETHING: | |
return doSomething(...args) | |
default: | |
break | |
} | |
} |
View Semaphore.js
import { Namespace } from '../core/Namespace' | |
export const internal = Namespace('Semaphore') | |
class Task { | |
constructor(semaphore, callback) { | |
const promises = [ | |
new Promise((resolve, reject) => { | |
this.resolve = resolve | |
this.reject = reject |
View Namespace.js
export function Namespace(name) { | |
const symbol = Symbol(name) | |
return function namespace(object, init = () => ({})) { | |
if (object[symbol] === undefined) { | |
object[symbol] = init() | |
} | |
return object[symbol] | |
} | |
} |
View gist:52b70edd4513edd8d034f2cd12d4bef9
class Multiplier { | |
constructor(value) { | |
const coefficient = value | |
return { | |
by(other) { | |
return other * coefficient | |
}, | |
} | |
} |
View gist:5253df331ed7003a230b41510bf0512b
class Base { | |
constructor() { | |
const privateVariable | |
this._protectedVariable | |
this.publicVariable | |
function privateFunction() {} | |
} | |
_protectedFunction() {} |
View gist:25567f766671e96b154bb7b0d0c5ec71
function Base() { | |
var privateVariable; | |
this._protectedVariable; | |
this.publicVariable; | |
function privateFunction() {} | |
} | |
Base.prototype._protectedFunction = function () {}; | |
Base.prototype.publicFunction = function () {}; |
View gist:c31ea61e9100738b9d23763a13d2b5d9
import Namespace from '../core/Namespace' | |
const self = undefined | |
const internal = Namespace() | |
class Task { | |
constructor(semaphore, callback) { | |
const promises = [ | |
new Promise((resolve, reject) => { | |
this.resolve = resolve |
View ratio_matrix.h
#include <array> | |
#include "ratio.h" | |
template < | |
class A_, class B_, class C_, | |
class D_, class E_, class F_, | |
class G_, class H_, class I_ | |
> | |
struct RatioMatrix { |
View ratio.h
#include <ratio> | |
namespace detail { | |
template <class... Args> | |
struct RatioAdd; | |
template <class R1, class R2> | |
struct RatioAdd<R1, R2> { | |
using Type = std::ratio_add<R1, R2>; |
View main.cpp
// Given | |
const auto size = ...; | |
auto begin = ...; | |
std::list<std::future<void>> futures; | |
const auto concurrency = std::thread::hardware_concurrency(); | |
const auto partition = std::imaxdiv(size, concurrency); | |
for (int i{}; i < concurrency; ++i) { | |
const auto end = begin + partition.quot + (i < partition.rem); | |
futures.emplace_back(std::async([this, begin, end]() { |
NewerOlder