Skip to content

Instantly share code, notes, and snippets.

@wiredprairie
wiredprairie / golang_contextWithTimeout.go
Last active September 29, 2020 13:26
Golang context.WithTimeout Demo
package main
import (
"context"
"fmt"
"time"
)
func main() {
wait := make(chan bool)
@wiredprairie
wiredprairie / zustand-initStore-experiement.ts
Created May 5, 2023 18:58
Experiment with Zustand initializer
function initStore<StoreTypes, Store extends UseBoundStore<StoreApi<unknown>>>(
store: Store,
compare?: (a: StoreTypes, b: StoreTypes) => boolean
) {
return (newValue: StoreTypes, defaultValue: StoreTypes) => {
if (compare && compare(newValue, store.getState() as unknown as StoreTypes)) {
return
}
store.setState(newValue as any)
}