ctx-core 5.32.1 → 5.33.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.
@@ -2,6 +2,10 @@ export declare class Cancel<R = unknown> extends Error {
2
2
  constructor(config?:Cancel_config_T<R>)
3
3
  returns:R
4
4
  }
5
+ export declare function promise__cancel<P extends Promise<unknown>>(
6
+ promise:P
7
+ ):P
8
+ export declare function promise__cancel__throw(promise:Promise<unknown>):void
5
9
  export type Cancel_config_T<R = unknown> = {
6
10
  message?:string
7
11
  returns?:R
@@ -1,6 +1,17 @@
1
1
  export class Cancel extends Error {
2
2
  constructor(config) {
3
3
  super(config?.message ?? 'Cancel')
4
+ this.name = 'Cancel'
4
5
  this.returns = config?.returns
5
6
  }
6
7
  }
8
+ export function promise__cancel(promise) {
9
+ promise.cancel?.()
10
+ promise.catch(()=>{})
11
+ return promise
12
+ }
13
+ export function promise__cancel__throw(promise) {
14
+ promise.cancel?.()
15
+ promise.catch(()=>{})
16
+ throw new Cancel
17
+ }
@@ -1,4 +1,3 @@
1
- import { waitfor } from '../waitfor/index.browser.js'
2
1
  /**
3
2
  * @param {string}path
4
3
  * @returns {Promise<boolean>}
@@ -11,18 +10,15 @@ export {
11
10
  file_exists_ as path__exists_
12
11
  }
13
12
  /**
14
- * @param {string}path
13
+ * @param {string|(()=>unknown|Promise<unknown>)}path_OR_op
15
14
  * @param {number}[timeout]
16
15
  * @param {number|((promise:waitfor_Promise<boolean>)=>Promise<number>)}[period]
17
16
  * @returns {Promise<boolean>}
18
17
  */
19
18
  export function file_exists__waitfor(
20
- path,
19
+ path_OR_op,
21
20
  timeout,
22
21
  period
23
22
  ) {
24
- return waitfor(()=>
25
- file_exists_(path),
26
- timeout ?? 5000,
27
- period ?? 0)
23
+ throw new Error('no browser support')
28
24
  }
@@ -4,7 +4,7 @@ export {
4
4
  file_exists_ as path__exists_
5
5
  }
6
6
  export declare function file_exists__waitfor(
7
- path:string,
7
+ path_OR_op:string|(()=>unknown|Promise<unknown>),
8
8
  timeout?:number,
9
9
  period?:number|((promise:waitfor_Promise<boolean>)=>Promise<number>)
10
10
  ):waitfor_Promise<boolean>
@@ -15,18 +15,30 @@ export {
15
15
  file_exists_ as path__exists_
16
16
  }
17
17
  /**
18
- * @param {string}path
18
+ * @param {string|(()=>unknown|Promise<unknown>)}path_OR_op
19
19
  * @param {number}[timeout]
20
20
  * @param {number|((promise:waitfor_Promise<boolean>)=>Promise<number>)}[period]
21
21
  * @returns {Promise<boolean>}
22
22
  */
23
23
  export function file_exists__waitfor(
24
- path,
24
+ path_OR_op,
25
25
  timeout,
26
26
  period
27
27
  ) {
28
- return waitfor(()=>
29
- file_exists_(path),
28
+ return waitfor(async ()=>{
29
+ // eslint-disable-next-line no-constant-condition
30
+ for (; 1;) {
31
+ try {
32
+ return await (
33
+ typeof path_OR_op === 'string'
34
+ ? file_exists_(path_OR_op)
35
+ : path_OR_op()
36
+ )
37
+ } catch (err) {
38
+ if (err.code !== 'ENOENT') throw err
39
+ }
40
+ }
41
+ },
30
42
  timeout ?? 5000,
31
43
  period ?? 0)
32
44
  }
@@ -46,7 +46,7 @@ test('file_exists_ + file_exists__waitfor|browser', async ()=>{
46
46
  await unlink(tempfile_path)
47
47
  }
48
48
  equal(await browser_file_exists_(tempfile_path), false)
49
- equal(err?.message, 'Timeout 10ms')
49
+ equal(err?.message, 'no browser support')
50
50
  })
51
51
  test('browser|build', async ()=>{
52
52
  await build({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ctx-core",
3
- "version": "5.32.1",
3
+ "version": "5.33.0",
4
4
  "description": "ctx-core core library",
5
5
  "keywords": [
6
6
  "ctx-core",
@@ -290,7 +290,7 @@
290
290
  "@arethetypeswrong/cli": "^0.13.6",
291
291
  "@ctx-core/preprocess": "^0.1.1",
292
292
  "@size-limit/preset-small-lib": "^11.0.2",
293
- "@types/node": "^20.11.8",
293
+ "@types/node": "^20.11.10",
294
294
  "@types/sinon": "^17.0.3",
295
295
  "c8": "^9.1.0",
296
296
  "check-dts": "^0.7.2",