Skip to content
Snippets Groups Projects
Commit 262ad37d authored by Xiao Gui's avatar Xiao Gui
Browse files

bugfix: pli desc

bugfix: race promise
parent 7dc89e6b
No related branches found
No related tags found
No related merge requests found
......@@ -142,7 +142,7 @@
throw new Error(`fn failed ${retries} times. Aborting.`)
}
exports.race = async (fn, { timeout = defaultConfig.timeout }) => {
exports.race = async (fn, { timeout = defaultConfig.timeout } = {}) => {
return Promise.race([
fn(),
new Promise((_rs, rj) => setTimeout(rj, timeout, `timed out: ${timeout}`))
......
import { getIdFromFullId, strToRgb, verifyPositionArg, arrayOrderedEql } from './util'
import { race, getIdFromFullId, strToRgb, verifyPositionArg, arrayOrderedEql } from './util'
describe('common/util.js', () => {
describe('getIdFromFullId', () => {
......@@ -150,4 +150,56 @@ describe('common/util.js', () => {
})
})
})
describe("> race", () => {
const defaultTimeout = 1000
describe("> without argument", () => {
it('> resolve should work', async () => {
await race(async () => {
await new Promise(rs => setTimeout(rs, 160, 'hello'))
})
expect(true).toEqual(true)
}),
it('> reject should work', async () => {
const start = performance.now()
try{
await race(async () => {
await new Promise(rs => setTimeout(rs, 5000, 'hello'))
})
expect(true).toEqual(false)
} catch (e) {
} finally {
const end = performance.now()
expect(end - start).toBeGreaterThan(defaultTimeout)
expect(end - start).toBeLessThan(defaultTimeout + 10)
}
})
})
describe("> with argument", () => {
const timeout = 500
it('> resolve should work', async () => {
await race(async () => {
await new Promise(rs => setTimeout(rs, 160, 'hello'))
}, { timeout })
expect(true).toEqual(true)
}),
it('> reject should work', async () => {
const start = performance.now()
try{
await race(async () => {
await new Promise(rs => setTimeout(rs, 1000, 'hello'))
}, { timeout } )
expect(true).toEqual(false)
} catch (e) {
} finally {
const end = performance.now()
expect(end - start).toBeGreaterThan(timeout)
expect(end - start).toBeLessThan(timeout + 10)
}
})
})
})
})
import { ChangeDetectionStrategy, ChangeDetectorRef, Component, ComponentFactory, ComponentFactoryResolver, Inject, Injector, Input, OnDestroy, Optional, TemplateRef, ViewChild, ViewContainerRef } from "@angular/core";
import { select, Store } from "@ngrx/store";
import { combineLatest, merge, NEVER, Observable, of, Subscription } from "rxjs";
import {catchError, debounceTime, distinctUntilChanged, map, shareReplay, startWith, switchMap, mapTo } from "rxjs/operators";
import {catchError, debounceTime, distinctUntilChanged, map, shareReplay, startWith, switchMap, mapTo, filter } from "rxjs/operators";
import { viewerStateSetSelectedRegions } from "src/services/state/viewerState/actions";
import {
viewerStateContextedSelectedRegionsSelector,
......@@ -207,16 +207,14 @@ export class ViewerCmp implements OnDestroy {
})
) || NEVER,
this._1umVoi$.pipe(
map(flag => flag
? ({
title: this._1umTitle,
description: this._1umDesc,
url: this._1umLink
? [{ doi: this._1umLink }]
: []
})
: null
)
filter(flag => flag),
map(() => ({
title: this._1umTitle,
description: this._1umDesc,
url: this._1umLink
? [{ doi: this._1umLink }]
: []
}))
)
)
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment