ctx-core 5.11.0 → 5.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/all/bind_apply/index.d.ts +26 -6
- package/all/bind_apply/index.js +5 -5
- package/all/bind_apply/index.test.ts +19 -0
- package/all/bind_call/index.d.ts +22 -4
- package/all/bind_call/index.js +1 -1
- package/all/bind_call/index.test.ts +18 -0
- package/all/call/index.d.ts +1 -1
- package/all/ctx/index.d.ts +1 -1
- package/all/index.d.ts +2 -3
- package/all/index.js +2 -3
- package/all/nullish__guard__async/index.js +1 -1
- package/all/nullish__none/index.d.ts +1 -1
- package/all/rmemo__wait/index.js +2 -2
- package/all/run/index.d.ts +0 -1
- package/all/run/index.js +0 -1
- package/all/tap/index.d.ts +9 -11
- package/all/tap/index.test.ts +10 -0
- package/all/timeout/index.d.ts +3 -0
- package/all/timeout/index.js +8 -0
- package/all/timeout/index.test.ts +8 -0
- package/all/timeout_promise/index.d.ts +7 -6
- package/all/timeout_promise/index.js +28 -8
- package/all/{promise_timeout → timeout_promise}/index.test.ts +9 -7
- package/all/tup/index.d.ts +0 -28
- package/all/tuple/index.d.ts +28 -0
- package/all/tuple/index.js +1 -0
- package/all/tuple__o/index.d.ts +2 -2
- package/all/tuple__union/index.d.ts +1 -1
- package/all/tuple_a_o/index.d.ts +1 -1
- package/all/waitfor/index.d.ts +1 -0
- package/all/waitfor/index.js +3 -2
- package/all/waitfor_fibonacci_backoff/index.js +4 -1
- package/all/zip__tuple_a/index.d.ts +2 -2
- package/falsy/index.d.ts +4 -0
- package/falsy/index.js +4 -0
- package/function/index.d.ts +5 -4
- package/function/index.js +5 -4
- package/nullish/index.d.ts +6 -0
- package/nullish/index.js +6 -0
- package/package.json +250 -239
- package/promise/index.d.ts +11 -0
- package/promise/index.js +11 -0
- package/rmemo/index.d.ts +8 -0
- package/rmemo/index.js +8 -0
- package/run/index.d.ts +12 -0
- package/run/index.js +12 -0
- package/tuple/index.d.ts +6 -0
- package/tuple/index.js +6 -0
- package/all/Timeout/index.d.ts +0 -1
- package/all/Timeout/index.js +0 -1
- package/all/promise_timeout/index.d.ts +0 -6
- package/all/promise_timeout/index.js +0 -30
- package/all/waitfor_val/index.d.ts +0 -6
- package/all/waitfor_val/index.js +0 -20
|
@@ -4,14 +4,34 @@ import type { call_fn_T } from '../call/index.js'
|
|
|
4
4
|
*/
|
|
5
5
|
export declare function bind_apply_<
|
|
6
6
|
Self,
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
A extends unknown[] = unknown[],
|
|
8
|
+
in_A extends unknown[] = unknown[],
|
|
9
|
+
O = unknown
|
|
10
10
|
>(
|
|
11
|
-
fn:call_fn_T<
|
|
12
|
-
|
|
11
|
+
fn:call_fn_T<A, O>,
|
|
12
|
+
self:Self,
|
|
13
|
+
in_arg_a?:bind_apply__in_arg_a_T<A, in_A>
|
|
14
|
+
):(...arg_a:bind_apply__out_arg_a_T<A, in_A>)=>O
|
|
13
15
|
export {
|
|
14
16
|
bind_apply_ as _bind_apply,
|
|
15
17
|
bind_apply_ as _apply__bind,
|
|
16
18
|
}
|
|
17
|
-
|
|
19
|
+
export type bind_apply__in_arg_a_T<
|
|
20
|
+
A extends unknown[],
|
|
21
|
+
in_A extends unknown[]
|
|
22
|
+
> =
|
|
23
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
24
|
+
A extends [...in_A, ...infer out_a]
|
|
25
|
+
? in_A
|
|
26
|
+
: never
|
|
27
|
+
export type bind_apply__out_arg_a_T<
|
|
28
|
+
A extends unknown[],
|
|
29
|
+
in_A extends unknown[]
|
|
30
|
+
> =
|
|
31
|
+
A extends [...in_A, ...infer out_A]
|
|
32
|
+
? [...in_A, ...out_A] extends A
|
|
33
|
+
? out_A
|
|
34
|
+
: in_A extends unknown[]
|
|
35
|
+
? A
|
|
36
|
+
: never
|
|
37
|
+
: never
|
package/all/bind_apply/index.js
CHANGED
|
@@ -2,14 +2,14 @@
|
|
|
2
2
|
/**
|
|
3
3
|
* Returns function bound to self that applies arg_a with ...arg_a_
|
|
4
4
|
* @param {call_fn_T}fn
|
|
5
|
-
* @param {unknown}
|
|
5
|
+
* @param {unknown}_this
|
|
6
6
|
* @param {unknown}[in_arg_a]
|
|
7
7
|
* @returns {(fn:call_fn_T, unknown, in_arg_a?:unknown[])=>ReturnType<call_fn_T>}
|
|
8
8
|
*/
|
|
9
|
-
export function bind_apply_(fn,
|
|
10
|
-
return (
|
|
11
|
-
...in_arg_a,
|
|
12
|
-
...
|
|
9
|
+
export function bind_apply_(fn, _this, in_arg_a) {
|
|
10
|
+
return (..._in_arg_a)=>fn.apply(_this, [
|
|
11
|
+
...in_arg_a ?? [],
|
|
12
|
+
..._in_arg_a
|
|
13
13
|
])
|
|
14
14
|
}
|
|
15
15
|
export {
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { test } from 'uvu'
|
|
2
|
+
import { equal } from 'uvu/assert'
|
|
3
|
+
import { tup } from '../tup/index.js'
|
|
4
|
+
import { bind_apply_ } from './index.js'
|
|
5
|
+
test('bind_apply_', ()=>{
|
|
6
|
+
function fn(this:unknown, a:number, b:number, c:number, d:number) {
|
|
7
|
+
return [this, a, b, c, d]
|
|
8
|
+
}
|
|
9
|
+
const _this = { foo: 'bar' }
|
|
10
|
+
equal(bind_apply_(fn, _this)(0, 1, 2, 3), [_this, 0, 1, 2, 3])
|
|
11
|
+
equal(bind_apply_(fn, _this, tup(0, 1))(2, 3), [_this, 0, 1, 2, 3])
|
|
12
|
+
// @ts-expect-error TS2345
|
|
13
|
+
equal(bind_apply_(fn, _this)(0, 1, 2, 3, 4), [_this, 0, 1, 2, 3])
|
|
14
|
+
// @ts-expect-error TS2345
|
|
15
|
+
equal(bind_apply_(fn, _this, tup(0, 1))(2, 3, 4), [_this, 0, 1, 2, 3])
|
|
16
|
+
// @ts-expect-error TS2345
|
|
17
|
+
equal(bind_apply_(fn, _this, tup(0, 1, 2, 3, 4))(), [_this, 0, 1, 2, 3])
|
|
18
|
+
})
|
|
19
|
+
test.run()
|
package/all/bind_call/index.d.ts
CHANGED
|
@@ -7,14 +7,32 @@ export {
|
|
|
7
7
|
* Returns function bound to self that calls ...in_arg_a concat with ...fn_arg_a passed to function
|
|
8
8
|
*/
|
|
9
9
|
export declare function bind_call_<
|
|
10
|
+
Self,
|
|
10
11
|
A extends unknown[] = unknown[],
|
|
11
|
-
|
|
12
|
-
|
|
12
|
+
in_A extends unknown[] = unknown[],
|
|
13
|
+
Out = unknown
|
|
13
14
|
>(
|
|
14
|
-
fn:call_fn_T<A,
|
|
15
|
-
|
|
15
|
+
fn:call_fn_T<A, Out>,
|
|
16
|
+
self:Self,
|
|
17
|
+
...in_arg_a:bind_call__in_arg_a_T<A, in_A>
|
|
18
|
+
):(...arg_a:[...bind_call__out_arg_a_T<A, in_A>])=>Out
|
|
16
19
|
export declare type bind_call_T<
|
|
17
20
|
A extends readonly unknown[] = readonly unknown[],
|
|
18
21
|
O = unknown
|
|
19
22
|
> = (...fn_arg_a:A)=>O
|
|
20
23
|
export declare type bind_call_type = bind_call_T
|
|
24
|
+
export type bind_call__in_arg_a_T<
|
|
25
|
+
A extends unknown[],
|
|
26
|
+
in_A extends unknown[]
|
|
27
|
+
> =
|
|
28
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
29
|
+
A extends [...in_A, ...infer Right]
|
|
30
|
+
? in_A
|
|
31
|
+
: never
|
|
32
|
+
export type bind_call__out_arg_a_T<
|
|
33
|
+
A extends unknown[],
|
|
34
|
+
in_A extends unknown[]
|
|
35
|
+
> =
|
|
36
|
+
A extends [...in_A, ...infer out_A]
|
|
37
|
+
? out_A
|
|
38
|
+
: never
|
package/all/bind_call/index.js
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* @returns {(fn:call_fn_T, self:unknown, ...in_arg_a:unknown[])=>ReturnType<call_fn_T>}
|
|
8
8
|
*/
|
|
9
9
|
export function bind_call_(fn, self, ...in_arg_a) {
|
|
10
|
-
return (...fn_arg_a)=>fn.
|
|
10
|
+
return (...fn_arg_a)=>fn.apply(self, [
|
|
11
11
|
...in_arg_a,
|
|
12
12
|
...fn_arg_a
|
|
13
13
|
])
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { test } from 'uvu'
|
|
2
|
+
import { equal } from 'uvu/assert'
|
|
3
|
+
import { bind_call_ } from './index.js'
|
|
4
|
+
test('bind_call_', ()=>{
|
|
5
|
+
function fn(this:unknown, a:number, b:number, c:number, d:number) {
|
|
6
|
+
return [this, a, b, c, d]
|
|
7
|
+
}
|
|
8
|
+
const _this = { foo: 'bar' }
|
|
9
|
+
equal(bind_call_(fn, _this)(0, 1, 2, 3), [_this, 0, 1, 2, 3])
|
|
10
|
+
equal(bind_call_(fn, _this, 0, 1)(2, 3), [_this, 0, 1, 2, 3])
|
|
11
|
+
// @ts-expect-error TS2345
|
|
12
|
+
equal(bind_call_(fn, _this)(0, 1, 2, 3, 4), [_this, 0, 1, 2, 3])
|
|
13
|
+
// @ts-expect-error TS2345
|
|
14
|
+
equal(bind_call_(fn, _this, 0, 1)(2, 3, 4), [_this, 0, 1, 2, 3])
|
|
15
|
+
// @ts-expect-error TS2345
|
|
16
|
+
equal(bind_call_(fn, _this, 0, 1, 2, 3, 4)(), [_this, 0, 1, 2, 3])
|
|
17
|
+
})
|
|
18
|
+
test.run()
|
package/all/call/index.d.ts
CHANGED
package/all/ctx/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Ctx } from '../be_/index.js'
|
|
2
|
-
import { TupleToUnion } from '../
|
|
2
|
+
import type { TupleToUnion } from '../tuple/index.js'
|
|
3
3
|
export declare function ctx__new():Ctx<''>
|
|
4
4
|
export { ctx__new as ctx_ }
|
|
5
5
|
export declare function ns_ctx__new<ns0_T extends string|Ctx, ns_a_T extends (string|Ctx)[]>(
|
package/all/index.d.ts
CHANGED
|
@@ -14,7 +14,6 @@ export * from './NumericUnit/index.js'
|
|
|
14
14
|
export * from './PHI/index.js'
|
|
15
15
|
export * from './Request/index.js'
|
|
16
16
|
export * from './Response/index.js'
|
|
17
|
-
export * from './Timeout/index.js'
|
|
18
17
|
export * from './VERSION/index.js'
|
|
19
18
|
export * from './a/index.js'
|
|
20
19
|
export * from './a_assign/index.js'
|
|
@@ -341,7 +340,6 @@ export * from './prev_idx/index.js'
|
|
|
341
340
|
export * from './primitive/index.js'
|
|
342
341
|
export * from './promise/index.js'
|
|
343
342
|
export * from './promise_o/index.js'
|
|
344
|
-
export * from './promise_timeout/index.js'
|
|
345
343
|
export * from './prototype/index.js'
|
|
346
344
|
export * from './prototype_mixin/index.js'
|
|
347
345
|
export * from './push/index.js'
|
|
@@ -406,6 +404,7 @@ export * from './throttle/index.js'
|
|
|
406
404
|
export * from './tick/index.js'
|
|
407
405
|
export * from './timedout/index.js'
|
|
408
406
|
export * from './timedout/index.js'
|
|
407
|
+
export * from './timeout/index.js'
|
|
409
408
|
export * from './timeout_promise/index.js'
|
|
410
409
|
export * from './times/index.js'
|
|
411
410
|
export * from './timestamp_ms/index.js'
|
|
@@ -413,6 +412,7 @@ export * from './timestamp_ms/index.js'
|
|
|
413
412
|
export * from './toLocalDateString/index.js'
|
|
414
413
|
export * from './toString/index.js'
|
|
415
414
|
export * from './tup/index.js'
|
|
415
|
+
export * from './tuple/index.js'
|
|
416
416
|
export * from './tuple__o/index.js'
|
|
417
417
|
export * from './tuple__union/index.js'
|
|
418
418
|
export * from './tuple_a_o/index.js'
|
|
@@ -442,7 +442,6 @@ export * from './valueof/index.js'
|
|
|
442
442
|
export * from './values/index.js'
|
|
443
443
|
export * from './waitfor/index.js'
|
|
444
444
|
export * from './waitfor_fibonacci_backoff/index.js'
|
|
445
|
-
export * from './waitfor_val/index.js'
|
|
446
445
|
export * from './weak_r/index.js'
|
|
447
446
|
export * from './week/index.js'
|
|
448
447
|
export * from './wrap_a/index.js'
|
package/all/index.js
CHANGED
|
@@ -14,7 +14,6 @@ export * from './NumericUnit/index.js'
|
|
|
14
14
|
export * from './PHI/index.js'
|
|
15
15
|
export * from './Request/index.js'
|
|
16
16
|
export * from './Response/index.js'
|
|
17
|
-
export * from './Timeout/index.js'
|
|
18
17
|
export * from './VERSION/index.js'
|
|
19
18
|
export * from './a/index.js'
|
|
20
19
|
export * from './a_assign/index.js'
|
|
@@ -341,7 +340,6 @@ export * from './prev_idx/index.js'
|
|
|
341
340
|
export * from './primitive/index.js'
|
|
342
341
|
export * from './promise/index.js'
|
|
343
342
|
export * from './promise_o/index.js'
|
|
344
|
-
export * from './promise_timeout/index.js'
|
|
345
343
|
export * from './prototype/index.js'
|
|
346
344
|
export * from './prototype_mixin/index.js'
|
|
347
345
|
export * from './push/index.js'
|
|
@@ -406,6 +404,7 @@ export * from './throttle/index.js'
|
|
|
406
404
|
export * from './tick/index.js'
|
|
407
405
|
export * from './timedout/index.js'
|
|
408
406
|
export * from './timedout/index.js'
|
|
407
|
+
export * from './timeout/index.js'
|
|
409
408
|
export * from './timeout_promise/index.js'
|
|
410
409
|
export * from './times/index.js'
|
|
411
410
|
export * from './timestamp_ms/index.js'
|
|
@@ -413,6 +412,7 @@ export * from './timestamp_ms/index.js'
|
|
|
413
412
|
export * from './toLocalDateString/index.js'
|
|
414
413
|
export * from './toString/index.js'
|
|
415
414
|
export * from './tup/index.js'
|
|
415
|
+
export * from './tuple/index.js'
|
|
416
416
|
export * from './tuple__o/index.js'
|
|
417
417
|
export * from './tuple__union/index.js'
|
|
418
418
|
export * from './tuple_a_o/index.js'
|
|
@@ -442,7 +442,6 @@ export * from './valueof/index.js'
|
|
|
442
442
|
export * from './values/index.js'
|
|
443
443
|
export * from './waitfor/index.js'
|
|
444
444
|
export * from './waitfor_fibonacci_backoff/index.js'
|
|
445
|
-
export * from './waitfor_val/index.js'
|
|
446
445
|
export * from './weak_r/index.js'
|
|
447
446
|
export * from './week/index.js'
|
|
448
447
|
export * from './wrap_a/index.js'
|
|
@@ -10,7 +10,7 @@ export async function nullish__guard__async(
|
|
|
10
10
|
const rv = await fn()
|
|
11
11
|
if (rv != null) return rv
|
|
12
12
|
}
|
|
13
|
-
throw
|
|
13
|
+
throw Error(`${label} cannot be nullish`)
|
|
14
14
|
}
|
|
15
15
|
export {
|
|
16
16
|
nullish__guard__async as nullish_async_guard,
|
package/all/rmemo__wait/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="../rmemo/index.d.ts" />
|
|
2
2
|
/// <reference types="./index.d.ts" />
|
|
3
|
-
import {
|
|
3
|
+
import { timeout_promise } from '../timeout_promise/index.js'
|
|
4
4
|
import { memo_ } from '../rmemo/index.js'
|
|
5
5
|
/**
|
|
6
6
|
* @param {rmemo_T}rmemo
|
|
@@ -26,7 +26,7 @@ export function rmemo__wait(
|
|
|
26
26
|
})
|
|
27
27
|
/** @type {cancel_Promise&{ m:memo_T<unknown> }} */
|
|
28
28
|
let promise =
|
|
29
|
-
|
|
29
|
+
timeout_promise(
|
|
30
30
|
_subscribe_wait,
|
|
31
31
|
timeout ?? Infinity,
|
|
32
32
|
error)
|
package/all/run/index.d.ts
CHANGED
package/all/run/index.js
CHANGED
package/all/tap/index.d.ts
CHANGED
|
@@ -1,20 +1,18 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Invokes interceptor with the
|
|
2
|
+
* Invokes interceptor with the val, and then returns the object.
|
|
3
3
|
* The primary purpose of this method is to "tap into" a method chain,
|
|
4
4
|
* to perform operations on intermediate results within the chain.
|
|
5
5
|
* @see {@link https://underscorejs.org/#tap}
|
|
6
6
|
*/
|
|
7
|
-
export declare function tap<
|
|
8
|
-
|
|
9
|
-
):
|
|
10
|
-
export declare type tap__interceptor_T<
|
|
11
|
-
export declare type tap_interceptor_T<
|
|
7
|
+
export declare function tap<V>(
|
|
8
|
+
val:V, interceptor:tap__interceptor_T<V>
|
|
9
|
+
):V
|
|
10
|
+
export declare type tap__interceptor_T<V = unknown> = (Val:V)=>void
|
|
11
|
+
export declare type tap_interceptor_T<V = unknown> = tap__interceptor_T<V>
|
|
12
12
|
/**
|
|
13
13
|
* Returns function that calls tap with obj.
|
|
14
14
|
*/
|
|
15
|
-
export declare function tap_<
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
fn:tap__interceptor_T<Val>
|
|
19
|
-
):(val:Val)=>Val
|
|
15
|
+
export declare function tap_<V = unknown>(
|
|
16
|
+
fn:tap__interceptor_T<V>
|
|
17
|
+
):(val:V)=>V
|
|
20
18
|
export { tap_ as _tap, }
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import type { cancel_Promise } from '../promise/index.js'
|
|
2
|
+
export declare function timeout_promise<O>(
|
|
3
|
+
promise:(()=>Promise<O>)|Promise<O>,
|
|
4
|
+
ms:number,
|
|
5
|
+
error?:Error
|
|
6
|
+
):cancel_Promise<O, (val?:O)=>Promise<O>>
|
|
7
|
+
export { timeout_promise as promise_timeout }
|
|
@@ -1,12 +1,32 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Timeout } from '../timeout/index.js'
|
|
2
2
|
/**
|
|
3
|
+
* @param {(()=>Promise<unknown>)|Promise<unknown>}promise
|
|
3
4
|
* @param {number}ms
|
|
4
|
-
* @param {
|
|
5
|
-
* @returns {
|
|
6
|
-
* @see {@link https://italonascimento.github.io/applying-a-timeout-to-your-promises/}
|
|
7
|
-
* @see {@link http://disq.us/p/1k8w63m}
|
|
5
|
+
* @param {Error}[error]
|
|
6
|
+
* @returns {cancel_Promise}
|
|
8
7
|
*/
|
|
9
|
-
export
|
|
10
|
-
|
|
8
|
+
export function timeout_promise(
|
|
9
|
+
promise,
|
|
10
|
+
ms,
|
|
11
|
+
error
|
|
12
|
+
) {
|
|
13
|
+
error ??= new Timeout(ms)
|
|
14
|
+
let id
|
|
15
|
+
let timeout = new Promise((_resolve, reject)=>{
|
|
16
|
+
id = setTimeout(()=>reject(error), ms)
|
|
17
|
+
})
|
|
18
|
+
let cancel_promise__resolve
|
|
19
|
+
let cancel_promise = new Promise(resolve=>cancel_promise__resolve = resolve)
|
|
20
|
+
/** @type {cancel_Promise} */
|
|
21
|
+
let ret_promise = Promise.race([
|
|
22
|
+
typeof promise === 'function' ? promise() : promise,
|
|
23
|
+
timeout,
|
|
24
|
+
cancel_promise,
|
|
25
|
+
]).then(result=>{
|
|
26
|
+
clearTimeout(id)
|
|
27
|
+
return result
|
|
28
|
+
})
|
|
29
|
+
ret_promise.cancel = cancel_promise__resolve
|
|
30
|
+
return ret_promise
|
|
11
31
|
}
|
|
12
|
-
export { timeout_promise as
|
|
32
|
+
export { timeout_promise as promise_timeout }
|
|
@@ -2,10 +2,11 @@ import { test } from 'uvu'
|
|
|
2
2
|
import { equal } from 'uvu/assert'
|
|
3
3
|
import { run } from '../run/index.js'
|
|
4
4
|
import { sleep } from '../sleep/index.js'
|
|
5
|
-
import {
|
|
6
|
-
|
|
5
|
+
import { Timeout } from '../timeout/index.js'
|
|
6
|
+
import { timeout_promise } from './index.js'
|
|
7
|
+
test('timeout_promise|success', async ()=>{
|
|
7
8
|
let count = 0
|
|
8
|
-
const promise =
|
|
9
|
+
const promise = timeout_promise(run(async ()=>{
|
|
9
10
|
count++
|
|
10
11
|
await sleep(10)
|
|
11
12
|
return true
|
|
@@ -14,11 +15,11 @@ test('promise_timeout|success', async ()=>{
|
|
|
14
15
|
equal(await promise, true)
|
|
15
16
|
equal(count, 1)
|
|
16
17
|
})
|
|
17
|
-
test('
|
|
18
|
+
test('timeout_promise|timeout', async ()=>{
|
|
18
19
|
let count = 0
|
|
19
20
|
let err:Error|undefined = undefined
|
|
20
21
|
try {
|
|
21
|
-
await
|
|
22
|
+
await timeout_promise(run(async ()=>{
|
|
22
23
|
count++
|
|
23
24
|
await sleep(10)
|
|
24
25
|
return false
|
|
@@ -27,10 +28,11 @@ test('promise_timeout|timeout', async ()=>{
|
|
|
27
28
|
err = _err as Error
|
|
28
29
|
}
|
|
29
30
|
equal(count, 1)
|
|
31
|
+
equal(err instanceof Timeout, true)
|
|
30
32
|
equal(err?.message, 'Timeout 1ms')
|
|
31
33
|
})
|
|
32
|
-
test('
|
|
33
|
-
const promise =
|
|
34
|
+
test('timeout_promise|cancel|arg', async ()=>{
|
|
35
|
+
const promise = timeout_promise(
|
|
34
36
|
new Promise<number>(()=>{}),
|
|
35
37
|
1000)
|
|
36
38
|
promise.cancel(5)
|
package/all/tup/index.d.ts
CHANGED
|
@@ -11,31 +11,3 @@ export {
|
|
|
11
11
|
tup as _tup,
|
|
12
12
|
tup as tup_fn,
|
|
13
13
|
}
|
|
14
|
-
export type TupleRest<T extends unknown[]> =
|
|
15
|
-
T['length'] extends 0
|
|
16
|
-
? undefined
|
|
17
|
-
: (((...b:T)=>void) extends (a:unknown, ...b:infer I)=>void ? I : [])
|
|
18
|
-
export type TupleFirst<T extends unknown[]> =
|
|
19
|
-
T['length'] extends 0 ? undefined : T[0]
|
|
20
|
-
export type TupleExclude<T extends unknown[], E> =
|
|
21
|
-
T extends []
|
|
22
|
-
? [Exclude<T, E>]
|
|
23
|
-
: T extends [infer Head, ...infer Tail]
|
|
24
|
-
? [Exclude<Head, E>, ...TupleExclude<Tail, E>]
|
|
25
|
-
: Exclude<T[number], E>[]
|
|
26
|
-
export type TupleMemberExtends<T extends Readonly<unknown[]>, E> =
|
|
27
|
-
T extends Readonly<[infer Head, ...infer Tail]>
|
|
28
|
-
? Head extends E
|
|
29
|
-
? true
|
|
30
|
-
: Tail extends unknown[]
|
|
31
|
-
? TupleMemberExtends<Tail, E>
|
|
32
|
-
: { ERROR:'Tail is not an array' }
|
|
33
|
-
: { ERROR:'Head does not extend E' }
|
|
34
|
-
export type TupleValues<T extends Readonly<unknown[]>> =
|
|
35
|
-
T extends Readonly<[infer Head, ...infer Tail]>
|
|
36
|
-
? [Head, ...Tail]
|
|
37
|
-
: { ERROR:'Unable to infer Head & Tail from T' }
|
|
38
|
-
export type TupleConcat<T> = T extends [infer A extends Readonly<unknown[]>, ...infer Rest extends Readonly<unknown[]>]
|
|
39
|
-
? A extends unknown[] ? [...A, ...TupleConcat<Rest>] : A
|
|
40
|
-
: T
|
|
41
|
-
export type TupleToUnion<T extends unknown[]> = T[number]
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export type TupleRest<T extends unknown[]> =
|
|
2
|
+
T['length'] extends 0
|
|
3
|
+
? undefined
|
|
4
|
+
: (((...b:T)=>void) extends (a:unknown, ...b:infer I)=>void ? I : [])
|
|
5
|
+
export type TupleFirst<T extends unknown[]> =
|
|
6
|
+
T['length'] extends 0 ? undefined : T[0]
|
|
7
|
+
export type TupleExclude<T extends unknown[], E> =
|
|
8
|
+
T extends []
|
|
9
|
+
? [Exclude<T, E>]
|
|
10
|
+
: T extends [infer Head, ...infer Tail]
|
|
11
|
+
? [Exclude<Head, E>, ...TupleExclude<Tail, E>]
|
|
12
|
+
: Exclude<T[number], E>[]
|
|
13
|
+
export type TupleMemberExtends<T extends Readonly<unknown[]>, E> =
|
|
14
|
+
T extends Readonly<[infer Head, ...infer Tail]>
|
|
15
|
+
? Head extends E
|
|
16
|
+
? true
|
|
17
|
+
: Tail extends unknown[]
|
|
18
|
+
? TupleMemberExtends<Tail, E>
|
|
19
|
+
: { ERROR:'Tail is not an array' }
|
|
20
|
+
: { ERROR:'Head does not extend E' }
|
|
21
|
+
export type TupleValues<T extends Readonly<unknown[]>> =
|
|
22
|
+
T extends Readonly<[infer Head, ...infer Tail]>
|
|
23
|
+
? [Head, ...Tail]
|
|
24
|
+
: { ERROR:'Unable to infer Head & Tail from T' }
|
|
25
|
+
export type TupleConcat<T> = T extends [infer A extends Readonly<unknown[]>, ...infer Rest extends Readonly<unknown[]>]
|
|
26
|
+
? A extends unknown[] ? [...A, ...TupleConcat<Rest>] : A
|
|
27
|
+
: T
|
|
28
|
+
export type TupleToUnion<T extends unknown[]> = T[number]
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {}
|
package/all/tuple__o/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export type tuple__o_T<
|
|
2
|
-
T extends readonly
|
|
2
|
+
T extends readonly unknown[],
|
|
3
3
|
Key extends keyof T[number],
|
|
4
4
|
Val extends keyof T[number]
|
|
5
5
|
> = {
|
|
6
|
-
[P in Exclude<keyof T, keyof readonly
|
|
6
|
+
[P in Exclude<keyof T, keyof readonly unknown[]> as T[P][Key]&string]:T[P][Val]
|
|
7
7
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export type tuple__union_T<T extends
|
|
1
|
+
export type tuple__union_T<T extends unknown[]> = T[number]
|
package/all/tuple_a_o/index.d.ts
CHANGED
package/all/waitfor/index.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ export declare function waitfor<V>(
|
|
|
4
4
|
timeout:number,
|
|
5
5
|
period?:number|((promise:waitfor_Promise<V>)=>Promise<number>)
|
|
6
6
|
):waitfor_Promise<V>
|
|
7
|
+
export { waitfor as waitfor_val, waitfor as waitfor_val_ }
|
|
7
8
|
export declare function cancel__period_<V>(
|
|
8
9
|
ms:number,
|
|
9
10
|
should_cancel_:()=>boolean
|
package/all/waitfor/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Cancel } from '../cancel/index.js'
|
|
2
|
-
import {
|
|
2
|
+
import { timeout_promise } from '../timeout_promise/index.js'
|
|
3
3
|
import { sleep } from '../sleep/index.js'
|
|
4
4
|
/**
|
|
5
5
|
* @param {()=>Promise<unknown>}fn
|
|
@@ -15,7 +15,7 @@ export function waitfor(
|
|
|
15
15
|
let rv
|
|
16
16
|
let cancel_arg_a
|
|
17
17
|
let promise = new Promise((resolve, reject)=>
|
|
18
|
-
|
|
18
|
+
timeout_promise(async ()=>{
|
|
19
19
|
for (; !cancel_arg_a;) {
|
|
20
20
|
let _rv = await fn()
|
|
21
21
|
rv = cancel_arg_a?.length ? cancel_arg_a[0] : _rv
|
|
@@ -39,6 +39,7 @@ export function waitfor(
|
|
|
39
39
|
}
|
|
40
40
|
return promise
|
|
41
41
|
}
|
|
42
|
+
export { waitfor as waitfor_val, waitfor as waitfor_val_ }
|
|
42
43
|
/**
|
|
43
44
|
* @param {number}ms
|
|
44
45
|
* @param {()=>boolean}should_cancel_
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { fibonacci_number_ } from '../fibonacci_number/index.js'
|
|
2
2
|
import { sleep } from '../sleep/index.js'
|
|
3
|
+
// TODO: Handle generic conditions.
|
|
4
|
+
// TODO: Then add to ./promise.
|
|
5
|
+
// TODO: Handle Response specific logic either with a function overload or with a separate function.
|
|
3
6
|
/**
|
|
4
7
|
* @param {()=>Promise<Response>}fn
|
|
5
8
|
* @param {number}[delay]
|
|
@@ -8,7 +11,7 @@ import { sleep } from '../sleep/index.js'
|
|
|
8
11
|
export async function waitfor_fibonacci_backoff(fn, delay = 500) {
|
|
9
12
|
let response
|
|
10
13
|
let delay_n = 1
|
|
11
|
-
|
|
14
|
+
for (;;) {
|
|
12
15
|
response = await fn()
|
|
13
16
|
if (response.status === 429) {
|
|
14
17
|
const fibonacci_number = fibonacci_number_(delay_n)
|
package/falsy/index.d.ts
ADDED
package/falsy/index.js
ADDED