Skip to content

Commit

Permalink
[skip ci] none
Browse files Browse the repository at this point in the history
  • Loading branch information
cmdcolin committed Nov 18, 2024
1 parent e46c501 commit aca1250
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 96 deletions.
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ yarn run v1.22.22 $ lerna-changelog --silent --silent --next-version 2.13.1
track selector in linear synteny view causing crash in v2.13.0
([@cmdcolin](https://github.com/cmdcolin))
- [#4495](https://github.com/GMOD/jbrowse-components/pull/4495) Fix log scale
for some types of stopToken tracks ([@cmdcolin](https://github.com/cmdcolin))
for some types of signal tracks ([@cmdcolin](https://github.com/cmdcolin))

#### Committers: 1

Expand Down Expand Up @@ -6437,7 +6437,7 @@ Broken releases missing some packages
rendering outside it's allowed bounds
([@cmdcolin](https://github.com/cmdcolin))
- [#1783](https://github.com/GMOD/jbrowse-components/pull/1783) Add hic
aborting and fix remoteAbort stopToken propagation
aborting and fix remoteAbort signal propagation
([@cmdcolin](https://github.com/cmdcolin))
- [#1723](https://github.com/GMOD/jbrowse-components/pull/1723) A few bugfixes
([@garrettjstevens](https://github.com/garrettjstevens))
Expand Down
23 changes: 21 additions & 2 deletions packages/core/assemblyManager/assembly.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ async function loadRefNameMap(
) {
const { sessionId } = options
await when(() => !!(assembly.regions && assembly.refNameAliases), {
stopToken,
name: 'when assembly ready',
})

Expand Down Expand Up @@ -157,11 +156,29 @@ export default function assemblyFactory(
configuration: types.safeReference(assemblyConfigType),
})
.volatile(() => ({
/**
* #volatile
*/
error: undefined as unknown,
/**
* #volatile
*/
loadingP: undefined as Promise<void> | undefined,
/**
* #volatile
*/
volatileRegions: undefined as BasicRegion[] | undefined,
/**
* #volatile
*/
refNameAliases: undefined as RefNameAliases | undefined,
/**
* #volatile
*/
lowerCaseRefNameAliases: undefined as RefNameAliases | undefined,
/**
* #volatile
*/
cytobands: undefined as Feature[] | undefined,
}))
.views(self => ({
Expand All @@ -175,6 +192,8 @@ export default function assemblyFactory(
.views(self => ({
/**
* #getter
* this is a getter with a side effect of loading the data. not the best
* practice, but it helps to lazy load the assembly
*/
get initialized() {
// @ts-expect-error
Expand Down Expand Up @@ -212,7 +231,7 @@ export default function assemblyFactory(
return self.getConf('displayName')
},
/**
* #getter
* #method
*/
hasName(name: string) {
return this.allAliases.includes(name)
Expand Down
86 changes: 1 addition & 85 deletions packages/core/util/when.ts
Original file line number Diff line number Diff line change
@@ -1,85 +1 @@
import { when as mobxWhen, IWhenOptions } from 'mobx'
import { checkStopToken } from './stopToken'

interface WhenOpts extends IWhenOptions {
stopToken?: string
}

/**
* Wrapper for mobx `when` that adds timeout and aborting support.
*/
export function when(
getter: () => boolean,
{ timeout, stopToken, name }: WhenOpts = {},
) {
return new Promise((resolve, reject) => {
let finished = false

const whenPromise = mobxWhen(getter)

// set up timeout
let timeoutId: ReturnType<typeof setTimeout> | undefined
let finishTimeout = () => {}
if (timeout) {
timeoutId = setTimeout(() => {
if (!finished) {
finished = true
whenPromise.cancel()
reject(new Error(`timed out waiting for ${name || 'whenPresent'}`))
}
}, timeout)
finishTimeout = () => {
if (timeoutId) {
clearTimeout(timeoutId)
}
}
}

// set up aborting
if (stopToken !== undefined) {
try {
checkStopToken(stopToken)
} catch (e) {
finished = true
whenPromise.cancel()
finishTimeout()
reject(new Error('aborted'))
}
}

whenPromise
.then(() => {
if (!finished) {
finished = true
finishTimeout()

resolve(true)
}
})
.catch((err: unknown) => {
if (!finished) {
finished = true
finishTimeout()
// eslint-disable-next-line @typescript-eslint/prefer-promise-reject-errors
reject(err)
}
})
})
}

/**
* Wrapper for mobx `when` that makes a promise for the return value
* of the given function at the point in time when it becomes not
* undefined and not null.
*/
export async function whenPresent<FUNCTION extends () => unknown>(
getter: FUNCTION,
opts: WhenOpts = {},
): Promise<NonNullable<ReturnType<FUNCTION>>> {
await when(() => {
const val = getter()
return val !== undefined && val !== null
}, opts)

return getter() as NonNullable<ReturnType<FUNCTION>>
}
export { when } from 'mobx'
3 changes: 2 additions & 1 deletion plugins/bed/src/generateBedMethylFeature.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,14 @@ export function generateBedMethylFeature({
n_diff,
n_nocall,
] = line.split('\t')

return {
uniqueId,
refName,
start,
end,
code,
score: fraction_modified,
score: +fraction_modified! || 0,
strand,
color,
source: code,
Expand Down
9 changes: 3 additions & 6 deletions plugins/wiggle/src/getMultiWiggleSourcesAutorun.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
import { autorun } from 'mobx'
import { addDisposer, isAlive } from 'mobx-state-tree'
// jbrowse
import {
getContainingView,
getSession,
isAbortException,
} from '@jbrowse/core/util'
import { getContainingView, getSession } from '@jbrowse/core/util'
import { LinearGenomeViewModel } from '@jbrowse/plugin-linear-genome-view'
import { AnyConfigurationModel } from '@jbrowse/core/configuration'
import { getRpcSessionId } from '@jbrowse/core/util/tracks'
import { isAbortException } from '@jbrowse/core/util/aborting'

export interface Source {
name: string
Expand Down Expand Up @@ -51,8 +48,8 @@ export function getMultiWiggleSourcesAutorun(self: {
self.setSources(sources)
}
} catch (e) {
console.error(e)
if (!isAbortException(e) && isAlive(self)) {
console.error(e)
getSession(self).notifyError(`${e}`, e)
}
}
Expand Down
13 changes: 13 additions & 0 deletions test_data/hs1/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,19 @@
}
},
"assemblyNames": ["hs1"]
},
{
"type": "FeatureTrack",
"trackId": "chm13v2.0_rmsk",
"name": "chm13v2.0_rmsk",
"adapter": {
"type": "BigBedAdapter",
"bigBedLocation": {
"uri": "https://hgdownload.soe.ucsc.edu/gbdb/hs1/t2tRepeatMasker/chm13v2.0_rmsk.bb",
"locationType": "UriLocation"
}
},
"assemblyNames": ["hs1"]
}
]
}

0 comments on commit aca1250

Please sign in to comment.