Browse Source

Libcore no longer need to run in queue

The fact we currently have SYNC_MAX_CONCURRENT obviously help.
Technically it should be possible to set SYNC_MAX_CONCURRENT to higher values, libcore should be fine,
but there is obviously an issue, so it will be up to core devs to investigate this, can set LEDGER_SYNC_MAX_CONCURRENT env var
master
Gaëtan Renaudeau 7 years ago
parent
commit
d1a74c447c
  1. 4
      src/bridge/BridgeSyncContext.js
  2. 3
      src/bridge/LibcoreBridge.js
  3. 10
      src/config/constants.js
  4. 10
      src/helpers/withLibcore.js

4
src/bridge/BridgeSyncContext.js

@ -15,7 +15,7 @@ import { setAccountSyncState } from 'actions/bridgeSync'
import { bridgeSyncSelector, syncStateLocalSelector } from 'reducers/bridgeSync'
import type { BridgeSyncState } from 'reducers/bridgeSync'
import { accountsSelector } from 'reducers/accounts'
import { SYNC_BOOT_DELAY, SYNC_ALL_INTERVAL } from 'config/constants'
import { SYNC_BOOT_DELAY, SYNC_ALL_INTERVAL, SYNC_MAX_CONCURRENT } from 'config/constants'
import { getBridgeForCurrency } from '.'
type BridgeSyncProviderProps = {
@ -87,7 +87,7 @@ class Provider extends Component<BridgeSyncProviderOwnProps, Sync> {
})
}
const syncQueue = priorityQueue(synchronize, 2)
const syncQueue = priorityQueue(synchronize, SYNC_MAX_CONCURRENT)
let skipUnderPriority: number = -1

3
src/bridge/LibcoreBridge.js

@ -1,5 +1,4 @@
// @flow
import logger from 'logger'
import React from 'react'
import { Observable } from 'rxjs'
import { map } from 'rxjs/operators'
@ -101,7 +100,7 @@ const LibcoreBridge: WalletBridge<Transaction> = {
})()
return {
unsubscribe() {
logger.warn('LibcoreBridge: unsub sync not implemented')
// LibcoreBridge: unsub sync not currently implemented
},
}
}),

10
src/config/constants.js

@ -1,12 +1,20 @@
// @flow
const intFromEnv = (key: string, def: number) => {
const v = process.env[key]
if (!isNaN(v)) return parseInt(v, 10)
return def
}
export const SYNC_MAX_CONCURRENT = intFromEnv('LEDGER_SYNC_MAX_CONCURRENT', 2)
export const SYNC_BOOT_DELAY = 2 * 1000
export const SYNC_ALL_INTERVAL = 60 * 1000
export const CHECK_APP_INTERVAL_WHEN_INVALID = 600
export const CHECK_APP_INTERVAL_WHEN_VALID = 1200
export const CHECK_UPDATE_DELAY = 5e3
export const DEVICE_DISCONNECT_DEBOUNCE = 1000
export const DEVICE_DISCONNECT_DEBOUNCE = intFromEnv('LEDGER_DEVICE_DISCONNECT_DEBOUNCE', 1000)
export const MODAL_ADD_ACCOUNT = 'MODAL_ADD_ACCOUNT'
export const MODAL_OPERATION_DETAILS = 'MODAL_OPERATION_DETAILS'

10
src/helpers/withLibcore.js

@ -1,12 +1,10 @@
// @flow
import invariant from 'invariant'
import logger from 'logger'
const core = require('@ledgerhq/ledger-core')
let walletPoolInstance: ?Object = null
let queue = Promise.resolve()
// TODO: `core` and `NJSWalletPool` should be typed
type Job<A> = (Object, Object) => Promise<A>
@ -21,11 +19,5 @@ export default function withLibcore<A>(job: Job<A>): Promise<A> {
const walletPool = walletPoolInstance
invariant(walletPool, 'core.instanciateWalletPool returned null !!')
const p = queue.then(() => job(core, walletPool))
queue = p.catch(e => {
logger.warn(`withLibCore: Error in job`, e)
})
return p
return job(core, walletPool)
}

Loading…
Cancel
Save