This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { | |
call, | |
createSignal, | |
each, | |
type Operation, | |
spawn, | |
type Stream, | |
suspend, | |
} from "effection"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { type Stream, createQueue, spawn } from "effection"; | |
/*/ | |
* @example | |
* let clicks: Stream<MousEvent> = pipe(on(button, 'click'), buffer(100)); | |
*/ | |
export function buffer<T, TClose>(limit: number): (stream: Stream<T, TClose>) => Stream<T, TClose> { | |
return function(stream) { | |
return { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { | |
createContext, | |
type Queue, | |
resource, | |
type Signal, | |
type Stream, | |
} from "https://deno.land/x/effection@3.0.0-beta.0/mod.ts"; | |
type Predicate = (value: unknown) => boolean; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { type Stream, type Operation, action, each, once, resource, spawn, createChannel, createSignal } from "effection"; | |
export interface WebSocketHandle extends Stream<MessageEvent, CloseEvent> { | |
send(value: string): Operation<void>; | |
close(code?: number, reason?: string): Operation<void>; | |
} | |
export function useWebSocket(url: string | URL, protocols?: string | string[]) { | |
return resource<WebSocketHandle>(function*(provide) { | |
let input = createChannel<string, {code?: number; reason?: string}>(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { action, spawn, sleep, type Operation } from "effection"; | |
export function* heartbeat(duration: number, op: () => Operation<unknown>): Operation<void> { | |
while (true) { | |
// this action captures a return point. | |
yield* action(function* (restart) { | |
// wait for the duration and return to the next loop iteration | |
yield* spawn(function*() { | |
yield* sleep(duration); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { run, type Operation } from "effection"; | |
import { useEffect, useState, type DependencyList } from "react"; | |
export type ResourceHandle<T> = { | |
type: 'pending'; | |
} | { | |
type: 'resolved'; | |
value: T; | |
} | { | |
type: 'rejected'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { type Computation, shift, reset } from "../deps.ts"; | |
import { type Resolve } from "../types.ts"; | |
export function* creatEvent<T>(): Computation<[Resolve<T>, Computation<T>]> { | |
let result: { value: T } | void = void 0; | |
let listeners: Resolve<T>[] = []; | |
let resolve = yield* reset<Resolve<T>>(function*() { | |
let value = yield* shift<T>(function*(k) { | |
return k.tail; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
async function sleep(duration) { | |
await new Promise(resolve => setTimeout(resolve, duration)); | |
} | |
async function main() { | |
await sleep(1000); | |
} | |
await main(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { each, main, sleep, spawn, createSignal } from "./mod.ts"; | |
await main(function*() { | |
let perf = globalThis.performance; | |
let signal = createSignal<string>(); | |
for (let i = 0; i < 1000; i ++) { | |
yield* spawn(function*() { |