MCPcopy
hub / github.com/yume-chan/ya-webadb / bipedal

Function bipedal

libraries/struct/src/bipedal.ts:30–65  ·  view source on GitHub ↗
(
    fn: BipedalGenerator<This, T, A>,
    bindThis?: This,
)

Source from the content-addressed store, hash-verified

28
29/* #__NO_SIDE_EFFECTS__ */
30export function bipedal<This, T, A extends unknown[]>(
31 fn: BipedalGenerator<This, T, A>,
32 bindThis?: This,
33): { (this: This, ...args: A): MaybePromiseLike<T> } {
34 function result(this: This, ...args: A): MaybePromiseLike<T> {
35 const iterator = fn.call(
36 this,
37 function* <U>(
38 value: MaybePromiseLike<U>,
39 ): Generator<
40 PromiseLike<U>,
41 U,
42 { resolved: U } | { error: unknown }
43 > {
44 if (isPromiseLike(value)) {
45 const result = yield value;
46 if ("resolved" in result) {
47 return result.resolved;
48 } else {
49 throw result.error;
50 }
51 }
52
53 return value;
54 },
55 ...args,
56 ) as never;
57 return advance(iterator, undefined);
58 }
59
60 if (bindThis) {
61 return result.bind(bindThis);
62 } else {
63 return result;
64 }
65}

Callers 5

AdbServerStreamClass · 0.90
index.jsFile · 0.90
structFunction · 0.85
_fieldFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected