Browse Source

Fix lint & actually return a correct observable from promise

master
Gaëtan Renaudeau 7 years ago
parent
commit
8c6577658c
  1. 9
      src/commands/libcoreHardReset.js
  2. 4
      src/helpers/hardReset.js

9
src/commands/libcoreHardReset.js

@ -1,20 +1,21 @@
// @flow // @flow
import { createCommand } from 'helpers/ipc' import { createCommand } from 'helpers/ipc'
import { Observable } from 'rxjs' import { fromPromise } from 'rxjs/observable/fromPromise'
import withLibcore from 'helpers/withLibcore' import withLibcore from 'helpers/withLibcore'
import createCustomErrorClass from 'helpers/createCustomErrorClass' import createCustomErrorClass from 'helpers/createCustomErrorClass'
const HardResetFail = createCustomErrorClass('HardResetFail') const HardResetFail = createCustomErrorClass('HardResetFail')
const cmd = createCommand('libcoreHardReset', () => const cmd = createCommand('libcoreHardReset', () =>
Observable.create(o => { fromPromise(
withLibcore(async core => { withLibcore(async core => {
const result = await core.getPoolInstance().eraseDataSince(new Date(0)) const result = await core.getPoolInstance().eraseDataSince(new Date(0))
if (result != core.ERROR_CODE.FUTURE_WAS_SUCCESSFULL) { if (result !== core.ERROR_CODE.FUTURE_WAS_SUCCESSFULL) {
throw new HardResetFail(`Hard reset fail with ${result} (check core.ERROR_CODE)`) throw new HardResetFail(`Hard reset fail with ${result} (check core.ERROR_CODE)`)
} }
})
}), }),
),
) )
export default cmd export default cmd

4
src/helpers/hardReset.js

@ -8,7 +8,9 @@ export default async function hardReset() {
// TODO: wait for the libcoreHardReset to be finished // TODO: wait for the libcoreHardReset to be finished
// actually, libcore doesnt goes back to js thread // actually, libcore doesnt goes back to js thread
await libcoreHardReset.send() await libcoreHardReset.send()
//await Promise.race([libcoreHardReset.send().toPromise(), delay(500)])
// await Promise.race([libcoreHardReset.send().toPromise(), delay(500)])
disableDBMiddleware() disableDBMiddleware()
db.resetAll() db.resetAll()
await delay(500) await delay(500)

Loading…
Cancel
Save