repos / starfx

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

starfx / fx
Eric Bower · 14 Nov 23

request.ts

 1import { call, useAbortSignal } from "../deps.ts";
 2
 3export function* request(url: string | URL | Request, opts?: RequestInit) {
 4  const signal = yield* useAbortSignal();
 5  const response = yield* call(fetch(url, { signal, ...opts }));
 6  return response;
 7}
 8
 9export function* json(response: Response) {
10  const result = yield* call(response.json());
11  return result;
12}