Published under the MIT license.
Made by @moheng233 and community 💛
# ✨ Auto-detect
npx nypm install @anyrpc/core
# npm
npm install @anyrpc/core
# yarn
yarn add @anyrpc/core
# pnpm
pnpm install @anyrpc/core
# bun
bun install @anyrpc/core
ESM (Node.js, Bun)
import { define, defineSSE } from "@moheng/anyrpc/server";
import { define, defineSSE, type SSEMessageEmit } from "@anyrpc/core/server";
/**
* @param start start at
* @param end end of
*/
export const hello = defineSSE(async (ev: SSEMessageEmit<string>, start: number, end: number) => {
console.log("test");
let count = start;
const interval = setInterval(async () => {
try {
const data = `hello world ${count}`;
await ev.emit(data, { id: count.toString() });
console.log(data);
count += 1;
if (count >= end) {
clearInterval(interval);
ev.close();
}
} catch (error) {
clearInterval(interval);
ev.close();
throw error;
}
}, 1000);
});
export const test = define(async (e: string) => {
});
import { hello } from './index.rpc'
const gen = await hello(0, 50)
const writable = gen.pipeTo(
new WritableStream({
abort(reason) {
const element = document.createElement('div')
element.textContent = `aborted: ${reason}`
document.querySelector('#view')?.appendChild(element)
},
close() {
const element = document.createElement('div')
element.textContent = 'closed'
document.querySelector('#view')?.appendChild(element)
},
start() {
const element = document.createElement('div')
element.textContent = 'started'
document.querySelector('#view')?.appendChild(element)
},
write(chunk) {
const element = document.createElement('div')
element.textContent = chunk.data
document.querySelector('#view')?.appendChild(element)
},
}),
)
🤖 auto updated with automd