mirror of
https://github.com/atom/atom.git
synced 2026-04-06 03:02:13 -04:00
Extract conditionPromise into async-spec-helpers
Signed-off-by: Nathan Sobo <nathan@github.com>
This commit is contained in:
committed by
Nathan Sobo
parent
ab3d0ba412
commit
82f0003302
@@ -29,6 +29,25 @@ export function afterEach (fn) {
|
||||
}
|
||||
})
|
||||
|
||||
export function conditionPromise (condition) {
|
||||
const timeoutError = new Error("Timed out waiting on condition")
|
||||
Error.captureStackTrace(timeoutError, conditionPromise)
|
||||
|
||||
return new Promise(function (resolve, reject) {
|
||||
const interval = global.setInterval(function () {
|
||||
if (condition()) {
|
||||
global.clearInterval(interval)
|
||||
global.clearTimeout(timeout)
|
||||
resolve()
|
||||
}
|
||||
}, 100)
|
||||
const timeout = global.setTimeout(function () {
|
||||
global.clearInterval(interval)
|
||||
reject(timeoutError)
|
||||
}, 5000)
|
||||
})
|
||||
}
|
||||
|
||||
function waitsForPromise (fn) {
|
||||
const promise = fn()
|
||||
// This timeout is 3 minutes. We need to bump it back down once we fix
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/** @babel */
|
||||
|
||||
import {it, fit, ffit, fffit, beforeEach, afterEach} from './async-spec-helpers'
|
||||
import {it, fit, ffit, fffit, beforeEach, afterEach, conditionPromise} from './async-spec-helpers'
|
||||
import TextEditorElement from '../src/text-editor-element'
|
||||
import _, {extend, flatten, last, toArray} from 'underscore-plus'
|
||||
|
||||
@@ -5085,25 +5085,6 @@ describe('TextEditorComponent', function () {
|
||||
}
|
||||
}
|
||||
|
||||
function conditionPromise (condition) {
|
||||
let timeoutError = new Error("Timed out waiting on condition")
|
||||
Error.captureStackTrace(timeoutError, conditionPromise)
|
||||
|
||||
return new Promise(function (resolve, reject) {
|
||||
let interval = window.setInterval(function () {
|
||||
if (condition()) {
|
||||
window.clearInterval(interval)
|
||||
window.clearTimeout(timeout)
|
||||
resolve()
|
||||
}
|
||||
}, 100)
|
||||
let timeout = window.setTimeout(function () {
|
||||
window.clearInterval(interval)
|
||||
reject(timeoutError)
|
||||
}, 5000)
|
||||
})
|
||||
}
|
||||
|
||||
function timeoutPromise (timeout) {
|
||||
return new Promise(function (resolve) {
|
||||
window.setTimeout(resolve, timeout)
|
||||
|
||||
Reference in New Issue
Block a user