-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split signals API and utils to separate exports
- Loading branch information
Showing
14 changed files
with
239 additions
and
150 deletions.
There are no files selected for viewing
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
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
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
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { Job, Yielding } from "./types.ts"; | ||
import { start } from "./jobutils.ts"; | ||
import { isValue, isError, markHandled } from "./results.ts"; | ||
import { isFunction } from "./utils.ts"; | ||
import { connect, Source } from "./streams.ts"; | ||
|
||
export function callOrWait<T>( | ||
source: any, method: string, handler: (job: Job<T>, val: T) => void, noArgs: (f?: any) => Yielding<T> | void | ||
) { | ||
if (source && isFunction(source[method])) return source[method]() as Yielding<T>; | ||
if (isFunction(source)) return ( | ||
source.length === 0 ? noArgs(source) : false | ||
) || start<T>(job => { | ||
connect(source as Source<T>, v => handler(job, v)).do(r => { | ||
if (isValue(r)) job.throw(new Error("Stream ended")); | ||
else if (isError(r)) job.throw(markHandled(r)); | ||
}); | ||
}); | ||
mustBeSourceOrSignal(); | ||
} | ||
|
||
export function mustBeSourceOrSignal() { throw new TypeError("not a source or signal"); } |
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
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
Oops, something went wrong.