What causes an error in RSVP Deferred when a promise is invoked multiple times?

What causes an error in RSVP Deferred when the promise is called twice?

There appears to be a distinction between

deferred.promise.then().finally()
and
deferred.promise.then(); deferred.promise.finally()
. Why is this?

RSVP.on('error', function(reason) {
  console.log('Error: ' + reason);
});

var deferred = RSVP.defer();
var deferred2 = RSVP.defer();
var deferred3 = RSVP.defer();
var promise3 = deferred3.promise;

deferred.promise.then(function() {
  console.log('Resolved');
}, function() {
  console.log('Rejected');
}).finally(function() {
  console.log('Finally');
});

deferred2.promise.then(function() {
  console.log('Resolved2');
}, function() {
  console.log('Rejected2');
});

deferred2.promise.finally(function() {
  console.log('Finally2');
});

promise3 = promise3.then(function() {
  console.log('Resolved3');
}, function() {
  console.log('Rejected');
});

promise3.finally(function() {
  console.log('Finally3');
});


deferred.reject('Reject!');
deferred2.reject('Reject2!');
deferred3.reject('Reject3!');
<script src="https://cdnjs.cloudflare.com/ajax/libs/rsvp/4.8.1/rsvp.js"></script>

UPDATE: I have identified how to resolve the problem. Check out the Deferred3 part in the code.

Answer №1

I discovered that using promise.then() (along with other methods) results in a modified promise, requiring you to chain the then, finally, catch... methods or save the promise each time.

RSVP.on('error', function(reason) {
  console.log('Error: ' + reason);
});

var deferred = RSVP.defer();
var promise = deferred.promise;

promise = promise.then(function() {
  console.log('Resolved');
}, function() {
  console.log('Rejected');
});

promise.finally(function() {
  console.log('Finally');
});


deferred.reject('Reject!');
<script src="https://cdnjs.cloudflare.com/ajax/libs/rsvp/4.8.1/rsvp.js"></script>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Exploring nested JSON objects with Jade and Express

Currently, I'm feeling a bit frustrated as I struggle to find a way to access the "media" content from this specific JSON object using Jade. { "summary":"Jose Mourinho names his Real Madrid side to face Borussia Dortmund in the Champions Lea ...

jQuery AJAX issues on Safari and iOS gadgets

I'm facing a compatibility issue specifically with Safari and all iOS devices. I've developed this jQuery code for a project, but it seems to have trouble working with Safari. Interestingly, it works perfectly fine with Chrome, Firefox, and even ...

There seems to be an issue with the functionality of the Bootstrap Modal

I've been working on incorporating bootstrap login Modal functionality into my code, but for some reason, the screen is not displaying it. Here's what shows up on the screen: https://i.sstatic.net/UIU2w.png The red box in the image indicates whe ...

Ways to send user input to a function within a React component

I am currently working on implementing a simple feature where users can search posts by their tags. To achieve this, I have created the Feed.jsx component with the following code: "use client"; import { useState, useEffect } from "react&quo ...

Categorize an array by shared values

Here is an example of my array structure: myArray = [ {SKU: "Hoo12", Name: "ACyrlic watch",OrderNo:"26423764233456"}, {SKU: "S0002", Name: "Princes Geometry",OrderNo:"124963805662313"}, {SKU ...

What is the process for obtaining a new token in a Linnworks embedded application?

I decided to share my issue on this platform since the support from Linnworks is virtually non-existent. My dilemma involves a private embedded app created within Linnworks that showcases orders in spreadsheet format. The app, constructed using Vue.js and ...

When making Axios GET requests, HTML receives promises that may remain empty

I've spent the entire day trying to figure out why this isn't working. Here's a simplified version of the HTML table using Vue v-for: <table id="timeSheet-datatable" class="table table-striped dt-responsive w-100"> ...

Using axios to make a request from a server to itself

I'm facing an issue where I am attempting to send a request from the server to the same server using axios as a PUT method. Here is an example of what I have tried: await axios({ url: `http://localhost:4000${url}`, method: requestType, ...

Managing an undetermined quantity of elements from a form in PHP

Currently developing an inventory page for my job. I've crafted a page that will iterate through my database and showcase all the items stored within. include 'auth.php'; //authentication required for login change $sql="SELECT * FROM `inven ...

Code Wizard

I am currently working on a project to develop an HTML editor. How it Needs to Function Elements Inside: Text Area - Used for typing HTML as text Iframe - Displays the typed HTML as real [renders string HTML to UI] Various Buttons Functionality: When ...

The collapsible section expands upon loading the page

Trying to implement Disqus as a plugin on my test webpage, I created a collapsible section with a "Show comments" button. The idea was to hide the plugin by default and reveal it only when users click on "Show comments". Despite using the w3schools example ...

What steps should be taken to effectively integrate Amplify Authenticator, Vue2, and Vite?

Embarked on a fresh Vue2 project with Vite as the build tool. My aim is to enforce user login through Cognito using Amplify. However, when I execute npm run dev, I encounter the following issue: VITE v3.1.3 ready in 405 ms ➜ Local: http://127.0.0 ...

What is the proper method for adding a file to formData prior to sending it to the server using a

I came across this tutorial on FormData, but I'm still trying to grasp how the formData object functions. Input Form Example: https://i.stack.imgur.com/h5Ubz.png <input type="file" id="file-id" class="w300px rounded4px" name="file" placeholder=" ...

The system encountered an error while trying to access the property "slug

I am currently working on a project that involves using next.js and wordpress. I have set up my api.js file, but I encountered an issue when trying to access the [slug] property from another component. The error message displayed is "Typerror: Cannot read ...

Guide on utilizing Vercel KV for storing and fetching posts from an API

Looking to optimize your API by utilizing Vercel KV for storing and retrieving posts? If you have a basic node.js express API that pulls random posts from MongoDB, the process of integrating Vercel KV can enhance performance. Initially, the API will resp ...

Wrapping dynamic page titles with comment tags in NextJS for cleaner code

I am currently working on NextJS version 12. In my project, I have a file named Layout.js which contains the following code: import Head from "next/head"; const Layout = ({children, pageTitle, mainClass}) => { return ( <> ...

Iterate over an array in JavaScript and include the elements as parameters in an SQL query

Can I set an SQL string to a variable in JavaScript and populate part of it by looping through an array? Here is the initial SQL: var tag = ["fun", "beach", "sun"]; var sql = "SELECT * FROM myTable " +"WHERE id > 5" //... // L ...

Creating an interactive timer that counts down in real-time using a combination of Django and JavaScript

When passing the date and time from views.py to my HTML page, I am encountering difficulties in utilizing that information to create a countdown timer using Javascript. For example: return render(request,'page.html',{'date':i.date,&apo ...

Unable to locate element in Internet Explorer when using frame switching within Selenium

I am currently working on a project in Selenium that is specifically designed to run in Internet Explorer, but I am encountering issues locating the xpath element. Despite this setback, I managed to make progress in the test by using the switch frame func ...

Convert Binary Data to PDF Using Javascript Through Streaming

Upon requesting a Web-service, I received the following response (PDF file Streamed) %PDF-1.5 %µµµµ 1 0 obj <</Type/Catalog/Pages 2 0 R/Lang(en-GB) /StructTreeRoot 10 0 R/MarkInfo<</Marked true>>>> endobj 2 0 obj <</Type/ ...