How to use p-settle - 5 common examples

To help you get started, we’ve selected a few p-settle examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github teppeis / duck / src / commands / buildJs.ts View on Github external
async function waitAllAndThrowIfAnyCompilationsFailed(
  promises: readonly Promise[],
  entryConfigPaths: readonly string[]
): Promise {
  const results = await pSettled(promises);
  const reasons: ErrorReason[] = results
    .map((result, idx) => ({
      ...result,
      entryConfigPath: entryConfigPaths[idx],
    }))
    .map(result => {
      if (result.isFulfilled) {
        // no errors, but it may contain warnings
        return {
          entryConfigPath: result.entryConfigPath,
          command: null,
          items: result.value || [],
        };
      } else {
        // has some errors
        const { message: stderr } = result.reason as CompilerError;
github sjbarag / brs / src / interpreter / index.ts View on Github external
public static async withSubEnvsFromComponents(
        componentMap: Map,
        parseFn: (filenames: string[]) => Promise,
        options: ExecutionOptions = defaultExecutionOptions
    ) {
        let interpreter = new Interpreter(options);
        interpreter.onError(getLoggerUsing(options.stderr));

        interpreter.environment.nodeDefMap = componentMap;

        let componentScopeResolver = new ComponentScopeResolver(componentMap, parseFn);
        await pSettle(
            Array.from(componentMap).map(async componentKV => {
                let [_, component] = componentKV;
                component.environment = interpreter.environment.createSubEnvironment(
                    /* includeModuleScope */ false
                );
                let statements = await componentScopeResolver.resolve(component);
                interpreter.inSubEnv(subInterpreter => {
                    subInterpreter.environment.setM(interpreter.environment.getM());
                    subInterpreter.exec(statements);
                    return BrsInvalid.Instance;
                }, component.environment);
            })
        );

        return interpreter;
    }
github Vizzuality / trase / frontend / scripts / actions / tool.actions.js View on Github external
geoJSON,
              getState().tool.nodesDict,
              getState().tool.geoIdsDict,
              geoColumn.id
            );
            return {
              geoJSON,
              ...vectorData
            };
          })
          .catch(() => Promise.reject(vectorLayerURL));
      }
      return Promise.resolve(vectorData);
    });

    pSettle(vectorMaps).then(results => {
      const mapVectorData = results
        .map(res => {
          if (res.isFulfilled && !res.isRejected) {
            return {
              ...res.value,
              isPoint:
                !!res.value.geoJSON &&
                !!res.value.geoJSON.features.length &&
                res.value.geoJSON.features[0].geometry.type === 'Point'
            };
          }
          console.warn('missing vector layer file', res.reason);
          return null;
        })
        .filter(item => item !== null);
      dispatch({
github iopipe / sqs-to-lambda-async / src / index.js View on Github external
sqs.receiveMessage(recieveArgs, (err, data) => {
      const messages = _.isArray(data.Messages) ? data.Messages : [];
      pSettle(
        messages.map(msg => {
          return handleMessage(msg, kwargs);
        })
      ).then(resolve);
    });
  });
github unboundedsystems / adapt / core / src / status.ts View on Github external
export async function mergeDefaultChildStatus<p>(
    props: P,
    parentStatus: object | Promise,
    mgr: ObserveForStatus,
    data: BuildData,
    transformParentStatus = noTransform): Promise {

    const childrenP = defaultChildStatus(props, mgr, data);
    const [ parentResult, childrenResult ] =
        await pSettle([ Promise.resolve(parentStatus), childrenP ]);

    if (childrenResult.isRejected) throw childrenResult.reason;
    const children: Status = childrenResult.value as any;
    if (children == null) throw new Error(`Error: status for children is null`);

    let stat: Status;
    if (parentResult.isFulfilled) {
        stat = transformParentStatus(parentResult.value);
    } else {
        const err = parentResult.reason;
        if (!ld.isError(err)) throw err;
        stat = (err instanceof MultiError &amp;&amp;
            err.errors.length === 1 &amp;&amp;
            err.errors[0].message) ?
            { noStatus: err.errors[0].message } :
            stat = { noStatus: err.message };</p>

p-settle

Settle promises concurrently and get their fulfillment value or rejection reason

MIT
Latest version published 8 months ago

Package Health Score

73 / 100
Full package analysis

Popular p-settle functions