Quantcast
Channel: Ember.JS - Latest topics
Viewing all articles
Browse latest Browse all 4835

Ember-Concurrency queue on task in component

$
0
0

@pjcarly wrote:

I have a problem with my current set-up, and i’m looking for some ideas or creative problem solving.

I have a model, with an attribute of type “file”, the “file” attribute is a custom type which stores an object with metadata of an uploaded file:

{ 
    "filename": "uploadedfile.jpg",
    "filesize": 121021010,
    "url": "http://mywebsite.com/file/uploadedfile.jpg"        
}

I have a custom component which handles the uploading of the file. You get a typical browse button, where you can browse your filesystem. After selecting a file, an ember-concurrency task is started, which uploads the file to an endpoint. After the task completes, the component returns the object (example above) which is then put in the attribute of the model. After which I can save the model, and file is then correctly attached to my model in my back-end.

In case the model doesn’t get saved, or the changes get cancelled. There is an automatic process deleting the uploaded files that didn’t get attached to any models. (this is a typical workflow in Drupal 8)

This is the situation. Now let me describe my problem.

In case someone is uploading a large file, it takes a while for the upload to complete. If someone clicks the save button that saves my model while the upload is still busy. I would like to queue the save behind the upload process. Because at the moment the save completes before the upload, and the file isn’t correctly linked to my model.

Now the problem is that my task that is uploading the file is encapsulated in a component. And the task saving the model is outside of the uploading component.

Is there a way of sharing the task or task instance, through a service or something, and how would I then queue my saving task behing the uploading task (possible multiple uploading tasks when there are multiple file fields on the model).

Posts: 3

Participants: 2

Read full topic


Viewing all articles
Browse latest Browse all 4835

Trending Articles