How to use rsvp - 10 common examples

To help you get started, we’ve selected a few rsvp 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 emberjs / ember-test-helpers / addon-test-support / @ember / test-helpers / -utils.ts View on Github external
/* globals Promise */

import RSVP from 'rsvp';
import hasEmberVersion from './has-ember-version';

export class _Promise extends RSVP.Promise {}

const ORIGINAL_RSVP_ASYNC: Function = RSVP.configure('async');

/*
  Long ago in a galaxy far far away, Ember forced RSVP.Promise to "resolve" on the Ember.run loop.
  At the time, this was meant to help ease pain with folks receiving the dreaded "auto-run" assertion
  during their tests, and to help ensure that promise resolution was coelesced to avoid "thrashing"
  of the DOM. Unfortunately, the result of this configuration is that code like the following behaves
  differently if using native `Promise` vs `RSVP.Promise`:

  ```js
  console.log('first');
  Ember.run(() => Promise.resolve().then(() => console.log('second')));
  console.log('third');

When Promise is the native promise that will log 'first', 'third', 'second', but when Promise is an RSVP.Promise that will log 'first', 'second', 'third'. The fact that RSVP.Promises can

github emberjs / ember-test-helpers / addon-test-support / @ember / test-helpers / -utils.ts View on Github external
be truthy. This is due to the fact that Ember has configured `RSVP` to resolve all promises in the run
  loop. What that means practically is this:

  1. all checks within `waitUntil` (used by `settled()` internally) are completed and we are "settled"
  2. `waitUntil` resolves the promise that it returned (to signify that the world is "settled")
  3. resolving the promise (since it is an `RSVP.Promise` and Ember has configured RSVP.Promise) creates
    a new Ember.run loop in order to resolve
  4. the presence of that new run loop means that we are no longer "settled"
  5. `isSettled()` returns false 😭😭😭😭😭😭😭😭😭

  This custom `RSVP.configure('async`, ...)` below provides a way to prevent the promises that are returned
  from `settled` from causing this "loop" and instead "just use normal Promise semantics".

  😩😫🙀
*/
RSVP.configure('async', (callback: any, promise: any) => {
  if (promise instanceof _Promise) {
    // @ts-ignore - avoid erroring about useless `Promise !== RSVP.Promise` comparison
    // (this handles when folks have polyfilled via Promise = Ember.RSVP.Promise)
    if (typeof Promise !== 'undefined' && Promise !== RSVP.Promise) {
      // use real native promise semantics whenever possible
      Promise.resolve().then(() => callback(promise));
    } else {
      // fallback to using RSVP's natural `asap` (**not** the fake
      // one configured by Ember...)
      RSVP.asap(callback, promise);
    }
  } else {
    // fall back to the normal Ember behavior
    ORIGINAL_RSVP_ASYNC(callback, promise);
  }
});
github ember-data / ember-data-filter / tests / test-helper.js View on Github external
QUnit.begin(() => {
  RSVP.configure('onerror', reason => {
    // only print error messages if they're exceptions;
    // otherwise, let a future turn of the event loop
    // handle the error.
    if (reason && reason instanceof Error) {
      throw reason;
    }
  });

  // Prevent all tests involving serialization to require a container
  DS.JSONSerializer.reopen({
    transformFor(attributeType) {
      return this._super(attributeType, true) || transforms[attributeType];
    }
  });

});
github emberjs / data / tests / test-helper.js View on Github external
QUnit.begin(() => {
  RSVP.configure('onerror', reason => {
    // only print error messages if they're exceptions;
    // otherwise, let a future turn of the event loop
    // handle the error.
    if (reason && reason instanceof Error) {
      throw reason;
    }
  });

  // Prevent all tests involving serialization to require a container
  // TODO kill the need for this
  DS.JSONSerializer.reopen({
    transformFor(attributeType) {
      return this._super(attributeType, true) || transforms[attributeType];
    },
  });
});
github discourse / discourse / app / assets / javascripts / discourse / widgets / widget.js.es6 View on Github external
if (view) {
      const method = view.get(name);
      if (!method) {
        // eslint-disable-next-line no-console
        console.warn(`${name} not found`);
        return;
      }

      if (typeof method === "string") {
        view[method](param);
        promise = Promise.resolve();
      } else {
        const target = view.get("target") || view;
        promise = method.call(target, param);
        if (!promise || !promise.then) {
          promise = Promise.resolve(promise);
        }
      }
    }

    return this.rerenderResult(() => promise);
  }
github 0dp / generator-wp-bones / libs / clone-bones.js View on Github external
'use strict';

// dependancies
var fs = require('fs');
var RSVP = require('rsvp');
var simpleGit = require('simple-git')();
var exec = require('child_process').exec;
var rmdir = require('rmdir');

// Bones git repo url
var bones = 'git://github.com/eddiemachado/bones.git';

// Configure RSVP promise to yell when something goes wrong
// --------------------------------------------------------
RSVP.on('error', function(e) {
  console.log(e.message);
  console.log(e.stack);
});

// Helper function to create a directory with a path given
// -------------------------------------------------------
var createDir = function (localPath, resolve, reject) {
  fs.mkdir(localPath, function (err) {
    if (err) {
      // if something goes wrong, tell the parent
      return reject(err);
    }
    // directory created, we can go on
    return resolve();
  });
};
github parkjs814 / DuoCoder / js / index.js View on Github external
const RSVP = require('rsvp');
const DOM = require('./dom');
const Server = require('./server');
const Storage = require('./storage');
const app = require('./app');
const App = require('./app/constructor');
const {Language} = require('./bean');
const {extend} = $;

const categories = Server.getCategories();
const from = 0, to = 1;

// set global promise error handler
RSVP.on('error', function (reason) {
  console.assert(false, reason);
});

extend(true, window, {
  main: DOM.setupMain,
  learn: () => {
    extend(true, app, new App());
    extend(true, window, {app});
    let lang_from_ext = getUrlParameter('lang_from');
    let lang_to_ext = getUrlParameter('lang_to');
    if (lang_from_ext && lang_to_ext) {
      const changed_from = Storage.language.set(from, lang_from_ext);
      const changed_to = Storage.language.set(to, lang_to_ext);
      if (changed_from || changed_to) Storage.category.set(categories[0].sub(0));
    } else {
      lang_from_ext = Storage.language.get(from);
github filamentgroup / directory-colorfy / lib / colorfy.js View on Github external
(function(){
	"use strict";

	var RSVP = require( 'rsvp' );
	var fs = require( 'fs-extra' );
	var path = require( 'path' );

	var workerFarm = require( '@filamentgroup/worker-farm' );
	var workers = workerFarm(require.resolve( path.join( __dirname, "convert" ) ) );

	RSVP.on( 'error', function(err){
		process.stderr.write( err.stack );
	});

	var colorsRegx = /\.colors\-([^\.]+)/i;

	var isColorWord = function( val ){
		var acceptable = ["black","silver","gray","white","maroon","red","purple","fuchsia","green","lime","olive","yellow","navy","blue","teal","aqua","aliceblue","antiquewhite","aqua","aquamarine","azure","beige","bisque","black","blanchedalmond","blue","blueviolet","brown","burlywood","cadetblue","chartreuse","chocolate","coral","cornflowerblue","cornsilk","crimson","cyan","darkblue","darkcyan","darkgoldenrod","darkgray","darkgreen","darkgrey","darkkhaki","darkmagenta","darkolivegreen","darkorange","darkorchid","darkred","darksalmon","darkseagreen","darkslateblue","darkslategray","darkslategrey","darkturquoise","darkviolet","deeppink","deepskyblue","dimgray","dimgrey","dodgerblue","firebrick","floralwhite","forestgreen","fuchsia","gainsboro","ghostwhite","gold","goldenrod","gray","green","greenyellow","grey","honeydew","hotpink","indianred","indigo","ivory","khaki","lavender","lavenderblush","lawngreen","lemonchiffon","lightblue","lightcoral","lightcyan","lightgoldenrodyellow","lightgray","lightgreen","lightgrey","lightpink","lightsalmon","lightseagreen","lightskyblue","lightslategray","lightslategrey","lightsteelblue","lightyellow","lime","limegreen","linen","magenta","maroon","mediumaquamarine","mediumblue","mediumorchid","mediumpurple","mediumseagreen","mediumslateblue","mediumspringgreen","mediumturquoise","mediumvioletred","midnightblue","mintcream","mistyrose","moccasin","navajowhite","navy","oldlace","olive","olivedrab","orange","orangered","orchid","palegoldenrod","palegreen","paleturquoise","palevioletred","papayawhip","peachpuff","peru","pink","plum","powderblue","purple","red","rosybrown","royalblue","saddlebrown","salmon","sandybrown","seagreen","seashell","sienna","silver","skyblue","slateblue","slategray","slategrey","snow","springgreen","steelblue","tan","teal","thistle","tomato","turquoise","violet","wheat","white","whitesmoke","yellow","yellowgreen"];
		return acceptable.indexOf( val ) > -1;
	};
	// test if value is a valid hex
	var isHex = function( val ){
		return (/^[0-9a-f]{3}(?:[0-9a-f]{3})?$/i).test( val );
	};


	var Colorfy = function( filepath, extraColors, opts ){
github algorithm-visualizer / algorithm-visualizer / js / index.js View on Github external
cache: false,
  dataType: 'text'
});

const {
  isScratchPaper
} = require('./utils');

const {
  getHashValue,
  getParameterByName,
  getPath
} = require('./server/helpers');

// set global promise error handler
RSVP.on('error', function (reason) {
  console.assert(false, reason);
});

$(() => {

  // initialize the application and attach in to the instance module
  const appConstructor = new AppConstructor();
  extend(true, app, appConstructor);

  // load modules to the global scope so they can be evaled
  extend(true, window, modules);

  Server.loadCategories().then((data) => {
    app.setCategories(data);
    DOM.addCategories();
github discourse / discourse / app / assets / javascripts / discourse / app / pre-initializers / discourse-bootstrap.js View on Github external
session.userColorSchemeId =
      parseInt(setupData.userColorSchemeId, 10) || null;
    session.userDarkSchemeId = parseInt(setupData.userDarkSchemeId, 10) || -1;

    let iconList = setupData.svgIconList;
    if (isDevelopment() && iconList) {
      setIconList(
        typeof iconList === "string" ? JSON.parse(iconList) : iconList
      );
    }

    if (setupData.s3BaseUrl) {
      setupS3CDN(setupData.s3BaseUrl, setupData.s3Cdn);
    }

    RSVP.configure("onerror", function (e) {
      // Ignore TransitionAborted exceptions that bubble up
      if (e && e.message === "TransitionAborted") {
        return;
      }

      if (!isProduction()) {
        /* eslint-disable no-console  */
        if (e) {
          if (e.message || e.stack) {
            console.log(e.message);
            console.log(e.stack);
          } else {
            console.log("Uncaught promise: ", e);
          }
        } else {
          console.log("A promise failed but was not caught.");