Skip to content

Commit e63d1bc

Browse files
author
Lucas
committed
feat: ⚡ 2x faster, critical fix on block detector, new serve({...}) to support new features like optimistic cache
1 parent e269db4 commit e63d1bc

File tree

12 files changed

+220
-226
lines changed

12 files changed

+220
-226
lines changed

.vscode/launch.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,23 @@
44
// Pour plus d'informations, visitez : https://go.microsoft.com/fwlink/?linkid=830387
55
"version": "0.2.0",
66
"configurations": [
7+
{
8+
"request": "launch",
9+
"name": "Launch Example",
10+
"type": "node",
11+
"program": "${workspaceFolder}/main.ts",
12+
"cwd": "${workspaceFolder}",
13+
"env": {},
14+
"runtimeExecutable": "/Users/lucas/.deno/bin/deno",
15+
"runtimeArgs": [
16+
"run",
17+
"--allow-all",
18+
"--unstable-ffi",
19+
"--inspect-brk",
20+
"${workspaceFolder}/examples/helloworld.ts"
21+
],
22+
"attachSimplePort": 9229
23+
},
724
{
825
"request": "launch",
926
"name": "Launch Program",

examples/helloworld.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const fns = new Fns({
66
dev: true,
77
baseUrl: "https://api.fns.run",
88
});
9-
fns.createFunction(
9+
const workflowtest = fns.createFunction(
1010
{ name: "WorkflowTest", version: 1 },
1111
() => {
1212
return async ({ step }) => {
@@ -21,7 +21,7 @@ fns.createFunction(
2121
};
2222
},
2323
);
24-
fns.createFunction(
24+
const realapitest = fns.createFunction(
2525
{ name: "helloworld", version: 1 },
2626
({ useState, useSignal }) => {
2727
const [name, setName] = useState<string>("name", "John Travolta");
@@ -44,17 +44,16 @@ fns.createFunction(
4444
.then((res) => res.name),
4545
);
4646

47-
await step.condition(
48-
"wait-until-name-is-good",
49-
() => name() === `${firstName} ${lastName}`,
50-
);
51-
5247
return `Hello ${firstName} ${lastName}`;
5348
};
5449
},
5550
);
5651
const app = express();
57-
app.use("/api-fns", express.raw({ type: "application/json" }), serve(fns));
52+
app.use(
53+
"/api-fns",
54+
express.raw({ type: "application/json" }),
55+
serve({ client: fns, functions: [workflowtest, realapitest] }),
56+
);
5857
app.use(express.json());
5958
app.get("/", (_, res) => res.json({ message: "Hello World" }));
6059
app.listen(3100, () => console.log("Server running on port 3100"));

libs/helper.ts

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,5 @@
1-
export const resolveNextTick = (timeouts: number[]) =>
2-
new Promise((resolve) => timeouts.push(Number(setTimeout(resolve, 0))));
3-
export async function execute(
4-
fn: Promise<unknown>,
5-
): Promise<[boolean, unknown]> {
6-
const timeouts: number[] = [];
7-
try {
8-
const result = await Promise.race([
9-
fn.then((data: unknown) => [true, data]),
10-
resolveNextTick(timeouts).then(() => [false, null]),
11-
]) as [boolean, unknown];
12-
return result;
13-
} catch (err) {
14-
throw err;
15-
} finally {
16-
for (let i = 0; i < timeouts.length; i++) {
17-
clearTimeout(timeouts[i]);
18-
}
19-
}
20-
}
211
export function block<T = unknown>(): Promise<T> {
22-
return new Promise(() => {});
2+
return new Promise<T>(() => {});
233
}
244

25-
export default { resolveNextTick, execute, block };
5+
export default { block };

libs/helper_bench.ts

Lines changed: 0 additions & 24 deletions
This file was deleted.

libs/helper_test.ts

Lines changed: 0 additions & 81 deletions
This file was deleted.

0 commit comments

Comments
 (0)