Skip to content

Instantly share code, notes, and snippets.

@alex35mil
alex35mil / hlc.rs
Created January 15, 2022 13:30
Hybrid Logical Clocks implementation in Rust
// Hybrid Logical Clocks implementation in Rust.
// Based on:
// - https://cse.buffalo.edu/tech-reports/2014-04.pdf
// - https://github.com/jlongster/crdt-example-app/blob/master/shared/timestamp.js
// - https://github.com/jaredly/hybrid-logical-clocks-example/blob/master/src/hlc.js
use std::{
char, cmp, fmt, num, ops, str,
time::{Duration, SystemTime, UNIX_EPOCH},
};

Promise.res

A slightly modified version of standard ReScript's Js.Promise module.

Key differences are:

  • t-first api
  • contains few helpers like Promise.result and Promise.wait (which is what I want most of the time in apps)

Soundness is on the same level as in the original bindings.

If you want more safety, consider reason-promise.

  1. Install these packages:
yarn install --dev @babel/core @babel/preset-env jest babel-jest
  1. Add babel.config.js (exactly babel.config.js, not .babelrc, not .babelrc.json etc):
module.exports = {
type transitionHook = Dom.htmlElement => unit;
module type Css = {
let duration: int;
let appear: string;
let enter: string;
let exit: string;
let appearActive: string;
let enterActive: string;
let exitActive: string;
open Belt;
type t(+'a) = Js.Promise.t('a);
type error = Js.Promise.error;
type result('ok, 'error) = t(Result.t('ok, 'error));
[@bs.new]
external make:
(
open Belt;
type t(+'a) = Js.Promise.t('a);
type error = Js.Promise.error;
type result('ok, 'error) = t(Result.t('ok, 'error));
external errorToString: error => string = "%identity";
[@bs.new]
@alex35mil
alex35mil / App.re
Last active May 24, 2020 13:55
FCM
<TextField
icon=(module IconOk)
value
onChange=change
/>
module Modifier = {
type t =
| Date(Js.Date.t)
| Range(Js.Date.t, Js.Date.t)
| Fn(Js.Date.t => bool);
let toJs =
(. x) =>
switch (x) {
| Date(date) => date
let all = Js.Promise.all;
let resolve = Js.Promise.resolve;
let reject = Js.Promise.reject;
let andThen =
(p: Js.Promise.t('a), fn: 'a => Js.Promise.t('b)): Js.Promise.t('b) =>
p->Js.Promise.then_(fn, _);