Пример #1
0
  return async dispatch => {
    let count = 0;
    const size = targetFiles.size;
    const promiseProducer = function () {
      if (count < size) {
        const f = targetFiles.get(count);
        const promise = addFile(f).then((mediaFile) => {
          dispatch(finishUpdate(mediaFile));
        });
        count++;
        return promise;
      } else {
        return null
      }
    };

    const pool = new PromisePool(promiseProducer, global.config.thumbnail.concurrency || 1)
    try {
      await pool.start();
    } catch (err) {
      console.warn(err);
    } finally {
      dispatch(finishAllUpdate());
      dispatch(listFiles());
    }
  };
Пример #2
0
const doActionConcurrency = (pluginNames, action, success, failure) => {
  const names = pluginNames.slice();
  const promiseProducer = () => {
    const name = names.shift();
    if (!name) {
      return;
    }
    return action(name).then(
      (result) => success(name, result)
    ).catch(
      (error) => failure(name, error)
    );
  };
  const pool = new PromisePool(promiseProducer, CONCURRENCY);
  pool.start();
};
  var pooledUpload = function(data) {
    var generatePromiseForPool = function() {
      if (!data.length) {
        return null;
      }

      var entry = data.shift();
      var collectResult = function(res) {
        results[entry] = res;
      };

      return fileToBin(entry, jsbin, options)
        .then(collectResult);
    };

    var pool = new PromisePool(generatePromiseForPool, options.concurrency);
    return pool.start().then(returnResults);
  };
Пример #4
0
    return new Promise( resolve => {
      const ElasticMapper = require( "./elastic_mapper" ); // eslint-disable-line global-require
      // map the ES response to a common data structure
      const data = ElasticMapper.csvFromResult( req, rsp );

      const tilestartTime = new Date( ).getTime( );
      // console.log( "saving tile caches" ); // eslint-disable-line no-console

      // figure out which map tile X,Y cells each result should be cached within
      // keep track of the array index of each result for each map tile key
      const cellIndicesByKey = { };
      _.each( data, ( datum, index ) => {
        const rowCells = TileCache.mapCellsForResult( req, datum );
        _.each( rowCells, cellKey => {
          cellIndicesByKey[cellKey] = cellIndicesByKey[cellKey] || [];
          cellIndicesByKey[cellKey].push( index );
        } );
      } );

      // set up the promise pool by creating a promise for each of the
      // map tile keys. Write up to 5 cell cache files at a time
      const cellIndicesKeys = _.keys( cellIndicesByKey );
      const promiseProducer = ( ) => {
        const cellKey = cellIndicesKeys.pop( );
        return cellKey ? TileCache.writeCellDataToCacheFile(
          req, cellKey, cellIndicesByKey[cellKey], data
        ) : null;
      };
      const pool = new PromisePool( promiseProducer, 5 );

      // start the promise pool to write the cell cache files
      pool.start( ).then( ( ) => {
        const tileendTime = new Date( ).getTime( );
        // eslint-disable-next-line no-console
        console.log( ["done saving tile caches", `took ${tileendTime - tilestartTime}ms`] );
        precisionCache.set( "saved.done", true, CACHE_DATA_TTL, ( ) => { } );
        resolve( );
      } );
    } );