Skip to content

Instantly share code, notes, and snippets.

View igalshilman's full-sized avatar

Igal Shilman igalshilman

View GitHub Profile

Effect Handlers in TypeScript

OCaml-style algebraic effects built on TypeScript generators. The fiber holds the iterator and a small state machine. The continuation is a one-shot, safety-checked handle. The handler is an async scheduler that drains synchronously-runnable work and parks while external wakers are pending.

Three pieces, each with one job:

  • Fiber<T> — iteration state machine

restate-sdk-gen internals: fibers, the scheduler, and the stack

A walkthrough of how user generators, fibers, and the scheduler interact in @restatedev/restate-sdk-gen. Aimed at JS engineers who already know Restate and durable execution; we skip framing on journals/replay and focus on the runtime model.

Source files referenced throughout:

  • src/scheduler.ts — orchestration

RocksDB SIGTRAP on Apple Silicon: Hardened libc++ vs Custom Aligned Allocators

Summary

RocksDB crashes with SIGTRAP (EXC_BREAKPOINT, brk #0x1) on Apple Silicon (aarch64-apple-darwin) when statistics are enabled. The crash occurs inside StatisticsImpl::recordTick or StatisticsImpl::recordInHistogram during normal database operations, including DB::Open.

The root cause is an incompatibility between Apple Clang's hardened libc++ bounds checking and RocksDB's custom cache-line-aligned allocator used by StatisticsData.

Symptoms

R = typing.TypeVar('R', bound=typing.Callable[..., typing.Awaitable[typing.Any]])
P = typing.ParamSpec('P'
def handler(func):
func._is_handler = True
return func
class Box:
__slots__ = ('value',)
import {
service,
serve,
type Context,
RestatePromise,
TerminalError,
} from "@restatedev/restate-sdk";
/***
* A durable async generator that persists its state across restarts.
import {
ObjectContext,
Rand,
service,
TerminalError,
type Context,
} from "@restatedev/restate-sdk";
class CircuitBreakerState {
constructor(
from fastapi import FastAPI
import restate
app = FastAPI()
@app.get("/")
async def foo():
return { "foo" : "bar" }
import { service, type Context } from "@restatedev/restate-sdk";
interface ServiceB {
greet: (ctx: Context, name: string) => Promise<string>;
}
const realServiceB = service({
name: "realServiceB",
handlers: {
export type Subscriber = {
service: string;
handler: string;
key?: string;
};
export const pubsub = restate.object({
name: "pubsub",
handlers: {
/**
import * as restate from "@restatedev/restate-sdk";
export type WorkItem = {
item: number; // compute item factorial
};
export type WorkRequest = {
awekable: string;
};