repos / starfx

supercharged async flow control library.
git clone https://github.com/neurosnap/starfx.git

commit
fc535da
parent
ce9ef2b
author
Eric Bower
date
2023-12-04 01:46:48 +0000 UTC
docs: readme
1 files changed,  +10, -1
M README.md
+10, -1
 1@@ -55,22 +55,31 @@ You didn't know you wanted express middleware for the front-end, but let me get
 2 you excited, it's powerful.
 3 
 4 ```ts
 5-import { createThunks, mdw } from "starfx";
 6+import { createThunks, mdw, call } from "starfx";
 7 
 8 const thunks = createThunks();
 9 // catch errors from task and logs them with extra info
10 thunks.use(mdw.err);
11 // where all the thunks get called in the middleware stack
12 thunks.use(thunks.routes());
13+thunks.use(function*(ctx, next) {
14+  console.log("last mdw in the stack");
15+});
16 
17 // create a thunk
18 const log = thunks.create("log", function* (ctx, next) {
19+  const resp = yield* call(fetch("https"//bower.sh"));;
20+  const data = yield* call(resp.json());
21   console.log("before calling next middleware");
22   yield* next();
23   console.log("after all remaining middleware have run");
24 });
25 
26 store.dispatch(log());
27+// output:
28+// before calling next middleware
29+// last mdw in the stack
30+// after all remaining middleware have run
31 ```
32 
33 # example: endpoints are tasks for managing HTTP requests