1// Copyright 2015 The Chromium OS Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5'use strict'; 6 7// This function will be used only when we need to wait for data gathering. 8function waitDuration(duration) { 9 return new Promise(function(resolve, reject) { 10 console.log('Waiting for ', duration.toString(), 'msec'); 11 setTimeout( 12 function() { 13 console.log('Done waiting'); 14 resolve(); 15 }, duration); 16 }); 17} 18 19function waitFor(description, predicate) { 20 return new Promise(function(resolve, reject) { 21 var startTime = new Date(); 22 console.log('Waiting for', description.toString()); 23 var check = setInterval(function() { 24 var elapsed = new Date() - startTime; 25 if (elapsed > 3000) { 26 startTime = new Date(); 27 console.log('Still waiting for satisfaction of ' + 28 predicate.toString()); 29 } else if (predicate()) { 30 clearInterval(check); 31 resolve(); 32 } 33 }, 50); 34 }); 35} 36 37