Testing
![formula](https://render.githubusercontent.com/render/math?math=e^{i \pi} = -1)
Testing
![formula](https://render.githubusercontent.com/render/math?math=e^{i \pi} = -1)
{"lastUpload":"2020-09-18T15:19:54.936Z","extensionVersion":"v3.4.3"} |
export const debouncedChunkedQueue = <T>( | |
fn: (items: T[]) => Promise<void> | void, | |
delay = 1000 | |
) => { | |
let items: T[] = [] | |
let started = false | |
const push = (item: T) => { | |
items.push(item) | |
if (!started) start() | |
} |
import { assert } from '../utils/assert' | |
export type Callback = (value: any, prevValue: any) => void | |
type DestroyCallback = () => void | |
interface ListenerNode { | |
parent: Symbol | ListenerNode | |
children: Record<string, ListenerNode> | |
prevValue: any |
Machine({ | |
id: 'Scroll view', | |
initial: 'chat_closed', | |
context: { | |
dog: null | |
}, | |
states: { | |
chat_closed: { | |
on: { | |
open: 'chat_open' |
const fs = require("fs"); | |
const acquireLock = async (identifier, retries = 5, delay = 1000) => { | |
const pathname = `${identifier}.lock`; | |
const acquire = () => { | |
try { | |
fs.mkdirSync(pathname); | |
return true; | |
} catch {} | |
}; |
Javascript is single threaded but it is not by any means immue to race conditions. Below is a swiss army knife of ways to deal with race conditions.
Single process
Multi process
UPDATE
commandsclass Foo { | |
public a string | |
public b number | |
} | |
function getDefault(fieldAsString: 'a' | 'b') { | |
if (field === 'a') return 'asdf' | |
if (field === 'b') return 3 | |
} |
class VersionedMap { | |
constructor(iterableOrMap, version = 0) { | |
this.map = | |
iterableOrMap instanceof Map ? iterableOrMap : new Map(iterableOrMap); | |
this.version = version; | |
this.mutated = false; | |
} | |
set(key, value) { | |
if (this.map.get(key) !== value) { |
import { createObservable as createObservableInner } from 'onin-shared/build/createObservable' | |
import { useEffect, useState } from 'react' | |
import { isMainThread } from './isMainThread' | |
export type Key = string | |
export type Value = string | undefined | |
const createObservable = (x: Value) => createObservableInner(x) | |
type Observable = ReturnType<typeof createObservable> | |
const Observables = { |