StaticClientThe MemFlow Client service is functionally
equivalent to the Temporal Client service.
StaticConnectionThe MemFlow Connection service is functionally
equivalent to the Temporal Connection service.
StaticHandleThe Handle provides methods to interact with a running workflow. This includes exporting the workflow, sending signals, and querying the state of the workflow. An instance of the Handle service is typically accessed via the MemFlow.Client class (workflow.getHandle).
StaticWorkerThe MemFlow Worker service is functionally
equivalent to the Temporal Worker service.
StaticdidChecks if an error is a HotMesh reserved error type that indicates a workflow interruption rather than a true error condition.
Checks if an error is a HotMesh reserved error type that indicates a HotMesh interruption rather than a true error condition.
When this returns true, you can safely return rethrow the error. The workflow engine will handle the interruption automatically.
The error to check
true if the error is a HotMesh interruption
StaticguidGenerate a unique identifier for workflow IDs
StaticregisterRegister activity workers for a task queue. Activities execute via message queue and can run on different servers from workflows.
Register activity workers for a task queue. Activities are invoked via message queue, so they can run on different servers from workflows.
The task queue name gets -activity appended automatically for the worker topic.
For example, taskQueue: 'payment' creates a worker listening on payment-activity.
Worker configuration (connection, namespace, taskQueue)
Activity functions to register
OptionalactivityTaskQueue: stringTask queue name (without -activity suffix).
Defaults to config.taskQueue if not provided.
Promise
// Activity worker (can be on separate server)
import { MemFlow } from '@hotmeshio/hotmesh';
import { Client as Postgres } from 'pg';
const activities = {
async processPayment(amount: number): Promise<string> {
return `Processed $${amount}`;
},
async sendEmail(to: string, subject: string): Promise<void> {
// Send email
}
};
await MemFlow.registerActivityWorker({
connection: {
class: Postgres,
options: { connectionString: 'postgresql://usr:pwd@localhost:5432/db' }
},
taskQueue: 'payment' // Listens on 'payment-activity'
}, activities, 'payment');
// Workflow worker (can be on different server)
async function orderWorkflow(orderId: string, amount: number) {
const { processPayment, sendEmail } = MemFlow.workflow.proxyActivities<{
processPayment: (amount: number) => Promise<string>;
sendEmail: (to: string, subject: string) => Promise<void>;
}>({
taskQueue: 'payment',
retryPolicy: { maximumAttempts: 3 }
});
const result = await processPayment(amount);
await sendEmail('customer@example.com', 'Order confirmed');
return result;
}
await MemFlow.Worker.create({
connection: {
class: Postgres,
options: { connectionString: 'postgresql://usr:pwd@localhost:5432/db' }
},
taskQueue: 'orders',
workflow: orderWorkflow
});
// Shared activity pool for interceptors
await MemFlow.registerActivityWorker({
connection: {
class: Postgres,
options: { connectionString: 'postgresql://usr:pwd@localhost:5432/db' }
},
taskQueue: 'shared'
}, { auditLog, collectMetrics }, 'shared');
const interceptor: WorkflowInterceptor = {
async execute(ctx, next) {
const { auditLog } = MemFlow.workflow.proxyActivities<{
auditLog: (id: string, action: string) => Promise<void>;
}>({
taskQueue: 'shared',
retryPolicy: { maximumAttempts: 3 }
});
await auditLog(ctx.get('workflowId'), 'started');
return next();
}
};
// Activity worker
const activities = {
async processPayment(amount: number) { return `Processed $${amount}`; },
async sendEmail(to: string, msg: string) { /* ... */ }
};
await MemFlow.registerActivityWorker({
connection: {
class: Postgres,
options: { connectionString: 'postgresql://usr:pwd@localhost:5432/db' }
},
taskQueue: 'payment'
}, activities, 'payment');
// Workflow worker (can be on different server)
async function orderWorkflow(amount: number) {
const { processPayment, sendEmail } = MemFlow.workflow.proxyActivities<{
processPayment: (amount: number) => Promise<string>;
sendEmail: (to: string, msg: string) => Promise<void>;
}>({
taskQueue: 'payment',
retryPolicy: { maximumAttempts: 3 }
});
const result = await processPayment(amount);
await sendEmail('customer@example.com', result);
return result;
}
await MemFlow.Worker.create({
connection: { class: Postgres, options: { connectionString: '...' } },
taskQueue: 'orders',
workflow: orderWorkflow
});
StaticworkflowThe MemFlow workflow service is functionally
equivalent to the Temporal Workflow service
with additional methods for managing workflows,
including: execChild, waitFor, sleep, etc
StaticclearStaticregisterRegister a workflow interceptor
The interceptor to register
Staticshutdown
The MemFlow service provides a Temporal-compatible workflow framework backed by Postgres. It offers durable execution, entity-based memory management, and composable workflows.
Core Features
1. Entity-Based Memory Model
Each workflow has a durable JSONB entity that serves as its memory:
2. Hook Functions & Workflow Coordination
Spawn and coordinate multiple perspectives/phases:
3. Durable Activities & Proxies
Define and execute durable activities with automatic retry:
4. Explicit Activity Registration
Register activity workers explicitly before workflows start:
5. Workflow Composition
Build complex workflows through composition:
6. Workflow Interceptors
Add cross-cutting concerns through interceptors that run as durable functions:
Basic Usage Example