mirror of
https://github.com/Foundry376/Mailspring.git
synced 2024-11-14 13:44:41 +08:00
c11a7ff830
Summary: Interrupt retryable syncback tasks that are taking too long so that we can return control to the sync loop. The sync loop will retry the task later. This diff adds a `forceReject` param to `interrupt()` so that we can return control immediately instead of waiting for the current operation to finish (for instance, the syncback task could be stuck in an imap operation, and a normal interrupt would still have to wait for that to finish before returning control to the callee) Part of T7978 Test Plan: specs Reviewers: evan, spang, mark, juan Reviewed By: juan Differential Revision: https://phab.nylas.com/D4269
21 lines
681 B
JavaScript
21 lines
681 B
JavaScript
import Interruptible from '../../src/shared/interruptible'
|
|
|
|
describe("Interruptible", () => {
|
|
describe("when interrupted with forceReject", () => {
|
|
it("the run method rejects immediately", async () => {
|
|
function* neverResolves() {
|
|
yield new Promise(() => {})
|
|
}
|
|
const interruptible = new Interruptible()
|
|
const promise = interruptible.run(neverResolves)
|
|
interruptible.interrupt({forceReject: true})
|
|
try {
|
|
await promise;
|
|
} catch (err) {
|
|
expect(/interrupted/i.test(err.toString())).toEqual(true)
|
|
}
|
|
// The promse never resolves, so if it doesn't reject,
|
|
// this test will timeout.
|
|
})
|
|
})
|
|
})
|