Skip to content

Commit

Permalink
Remove unused wrapForRpc functionality (#2324)
Browse files Browse the repository at this point in the history
  • Loading branch information
cmdcolin committed Sep 22, 2021
1 parent 5769c7e commit 77f6c7a
Showing 1 changed file with 23 additions and 57 deletions.
80 changes: 23 additions & 57 deletions products/jbrowse-web/src/rpc.worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import { useStaticRendering } from 'mobx-react'

import PluginManager from '@jbrowse/core/PluginManager'
import { remoteAbortRpcHandler } from '@jbrowse/core/rpc/remoteAbortSignals'
import { isAbortException } from '@jbrowse/core/util'
import RpcMethodType from '@jbrowse/core/pluggableElementTypes/RpcMethodType'
import PluginLoader, { PluginDefinition } from '@jbrowse/core/PluginLoader'
import corePlugins from './corePlugins'

Expand All @@ -23,8 +21,8 @@ interface WorkerConfiguration {

let jbPluginManager: PluginManager | undefined

// waits for a message from the main thread containing our configuration,
// which must be sent on boot
// waits for a message from the main thread containing our configuration, which
// must be sent on boot
function receiveConfiguration(): Promise<WorkerConfiguration> {
return new Promise(resolve => {
// listen for the configuration
Expand All @@ -45,9 +43,7 @@ async function getPluginManager() {
pluginLoader.installGlobalReExports(self)
const runtimePlugins = await pluginLoader.load()
const plugins = [...corePlugins.map(p => ({ plugin: p })), ...runtimePlugins]
const pluginManager = new PluginManager(
plugins.map(({ plugin: P }) => new P()),
)
const pluginManager = new PluginManager(plugins.map(P => new P.plugin()))
pluginManager.createPluggableElements()
pluginManager.configure()
jbPluginManager = pluginManager
Expand All @@ -60,62 +56,32 @@ interface WrappedFuncArgs {
[key: string]: unknown
}

let callCounter = 0
function wrapForRpc(
func: (args: unknown, rpcDriverClassName: string) => unknown,
funcName: string = func.name,
) {
return (args: WrappedFuncArgs) => {
callCounter += 1
const myId = callCounter
// logBuffer.push(['rpc-call', myId, funcName, args])
const retP = Promise.resolve()
.then(() => getPluginManager())
.then(() =>
func(
{
...args,
statusCallback: (message: string) => {
// @ts-ignore
self.rpcServer.emit(args.channel, message)
},
},
args.rpcDriverClassName,
),
)
.catch(error => {
if (isAbortException(error)) {
// logBuffer.push(['rpc-abort', myId, funcName, args])
} else {
console.error('rpc-error', myId, funcName, error)
}
throw error
})
type RpcFunc = (args: unknown, rpcDriverClassName: string) => unknown

// uncomment below to log returns
// retP.then(
// result => logBuffer.push(['rpc-return', myId, funcName, result]),
// err => {},
// )

return retP
function wrapForRpc(func: RpcFunc) {
return (args: WrappedFuncArgs) => {
const { channel, rpcDriverClassName } = args
return func(
{
...args,
statusCallback: (message: string) => {
// @ts-ignore
self.rpcServer.emit(channel, message)
},
},
rpcDriverClassName,
)
}
}

getPluginManager()
.then(pluginManager => {
const rpcConfig: { [methodName: string]: Function } = {}
const rpcMethods = pluginManager.getElementTypesInGroup('rpc method')
rpcMethods.forEach(rpcMethod => {
if (!(rpcMethod instanceof RpcMethodType)) {
throw new Error('invalid rpc method??')
}

rpcConfig[rpcMethod.name] = wrapForRpc(
rpcMethod.execute.bind(rpcMethod),
rpcMethod.name,
)
})
const rpcConfig = Object.fromEntries(
pluginManager.getElementTypesInGroup('rpc method').map(entry => {
const { execute, name } = entry
return [name, wrapForRpc((execute as RpcFunc).bind(entry))]
}),
)

// @ts-ignore
self.rpcServer = new RpcServer.Server({
Expand Down

0 comments on commit 77f6c7a

Please sign in to comment.