Hey guys welcome back.
Intellectually good the theory that the user after a successful creational block in the like to continue
this issue.
We are currently having some of I'm spatting we say about them and sending multiple requests even though
I am disabling this button here.
Salatin it pricked up and let panic button.
There you can see I created just now allowed to dream for a blog post and this is not very good.
So let's fix it and go back to our rebirths.
We need a fix on our server side so to go to our server folder QUANTRILL or as a block of dodgiest and
create a block function here so what we can do here we can arrive here write some kind of a statement
and check if the user are not sending requests.
He's already saving block and he was already sending a blog we don't want to allow to save his blog.
Again this can be a little bit difficult and a lot of code.
So what we can do actually.
We can use the locks so our.
Let's go back to our browsers and let's search for a single NPM package.
So we'll go and out of the right here is the lock and PM and here seeing does lock and the package.
OK so we can write documentation here.
And let's see this lock and sinker.
Scott purrfect all right and let's see maybe there is some news for a description here.
OK maybe not but what is luck is doing.
If you will wrap your code into all of this look code.
Next request will not be around until this lock is not released.
So here you can see all users a lot.
Acquiring the real up right here are some kein some malarkey.
And then you can run your own function when the function is done.
So you would call this function.
Damn this lock is released and then you can call again this function.
But until this point you cannot call this function.
So then some other ECOs will come here and you will try to exit gudis luck here indeed you are not around
to fail.
So he will just wait years Samaa seconds.
All are done here and don't look is open but Balbi have time to redirect the user.
So yeah let's do it let's install this look and it will be much cleaner in our code.
So first let's find common for installing it here maybe maybe not.
But OK on the earth.
So we need to just install a single large lock.
So let's go back to our terminals and once around here NPM install Didache safe and a single dash lock
and that could be it from installation.
Go back to our browsers and let's copy this code so a single on here back to our readers and let's paste
it up here.
UPS of Leglise.
OK let's send it for icons and DS for a concert is about perfect.
Let's continue and go back to a browser and let's see what function we can use and actually what about
error handling here.
OK we don't need these options.
OK I think up here we can use these function jobs here so I will copy the function here and specify
dolma.
OK I will use these Bondies but there are examples for a starting here.
So legatees just copy this function and go back to our coding a dress and paste it inside.
Create a block function like it is perfect.
Let in and they do it right side and let's see what we have.
Or something is called a function of the error and the return is called when your lock is released so
many roll call done a function up here.
OK so here I just want to check for an error and a Consoli to look out.
So if error or just console the lock error or you can rewrite it like this.
Error or logical operator and and a console lock error or other console error or error.
Calliope's was always first man for effect.
You can specify here some more options but I don't eat for an hour.
So as I remove these options Leglise OK and here is our main functionality.
The spacing more here.
So let's make some space and let God be our main functionally doing so our saving to the block post.
Let's go to all of these guys from here and let Bastet inside of these lockpick liar case here let add
it to the right side so it's correct annelids removed.
Also these don't function is nung function.
Now again like your evil is empty lines and you can call these a function of an hour a block is saved.
So Angel of the saved blog is this callback function I go here don't function like this or other I can
call it after some time so it's specify a set timeout so set timeout.
I was by your time I.
5 seconds.
So instead of let's see if I go the function and I want to execute It's called a function in five seconds
so five thousand milliseconds.
And I want to go here don't function.
So done like this.
All right I can remove this records and that should be perfect.
So what we are missing here and actually we are missing here is key and these needs to come from our
clients.
So I am sending it was.
I want to send here also key to Lagasse's function because if some other user is sending same request
the same time I don't want to log this for other user.
So that's why I need to provide some specific key for a user.
OK so let's Evis file.
Now let's go to our ages and to find here our block entered dodgiest.
And here we can specify some Kiem.
So up here in this state I will specify let's say lock I.D. and you're able to generate some on numeric
key.
So far either to go back to our browsers and I prepared for you so does Google these generate for and
the numbers scripts.
Very simple and you should probably find these stack overflow billing here.
So it's like this.
And here is just very simple I'm not sure and not around on function.
So a'la copy capitis arcane and I will include the link into the very source of the lecture so I'll
go back to I can agree Thoreau's And let's face it here.
So much for the man around them.
And they should generate four digit around on number.
OK.
So look at the need to provide this.
Look I mean do I create a block.
So all of these look at it here so present it from a state.
So up here in the STB looking at the right cost structure eyes look I mean like this and get it from
a state to this state traffic lights and is log ID requests or create a block and probably also look
I quite serious and want to go through our actions or actions in those areas.
Now let's get these look the function down here.
So create a block and you will get your olso look IDM and let's rewrite these requests.
So I want to send the database to slash the locks and also provide very very parameters.
So you can specify a parameter of this.
So a question mark and now look Id equals.
Now Dora Santley brackets and I want to interpolate is Melli of the lock IDs so these are random number
like these.
Perfect.
So let's say this and we need to get these look Id on our server side back.
So let's go back to our server.
So our block are just to create a blog and what we get is look at a year sale right here because look
at the cost and you can get these look at the From request and Querrey and and now look Id because we
specify very public ID right.
So let's see one more time.
It was here we are sending these look Id so we can get it look Id here from a very small request very
long.
All right.
And now he can pass his look ID to our choir.
Look at it here.
Perfect.
Let's say this let's go back to our terminals and let's start up our servers so NPM around.
And let's see if it's working.
All rights are compiled.
And let's see.
So back to our browsers their applications.
And let's go to our blog editorial page.
So here and make sure your lap is empty so no block on your side or Deely one more time here.
There will be one person sure that I don't have any block calls here.
So let's see here.
OK.
No documents here.
Perfect.
Let's go back to our obligations and let's try to spam these buttons say.
So say OK and I sent three requests OK so you can see and actually Dugald is just like any request I
just send the request please look Id here and look Id here.
I will make it slightly bigger so I can see your and Randy's success school in a way that is not resolved.
Perfect.
So see our lab and we should have just about those your referees page
and Azzi and we are actually to block Pozieres or something is not very good in our code.
Okay this is improvement.
The last time we are under that and we just get to block those but is not very good.
So lets go back to work on gaters and if we can right here and check also for these I will show you
what you can to use here and you can use here look its a busy so many look is busy you dont want to
perform there are safe or block in the game so we can use this function here.
Look is busy being subject to our editors and what I write here is check.
So before we are saving anything.
All right there is a look he's busy and we want to check here also for our king.
So let's go right here.
Look I don't like this.
They want to perform this action and actually look is not easy to save these.
So if a lock is not too busy you have to save all of this.
OK so let's go pee.
All of this gold inside of this E-block hole like this.
All right OK.
They should be feeling more like like this.
And let's use that as a block so there should be else here.
If your hero is right.
Else.
So if Locke is busy I want to return some other responses that are either on your or Eterna response
not staler us.
We can write your status up to you four hundred twenty two.
And let's send it back to those empty objects can ride here.
Maybe some message or error.
It's up to you.
Message.
Block is saving.
All right.
So Leglise let's Abeles and let's go back to our terminals.
Let's refresh our server and let's go back to our browsers
OK so we can go to our Emel up and if we can remove all of our documents so now let's make sure everything
is working correctly.
OK.
So delete everything.
I have a zero block goes here.
Let's go back to our application and let's refresh Also this and we will try to spam the save button
so it'll make it.
And we just remove our story.
So we need to go to our blog editor or page gets a block and it's our
All right let's wait to go out with these puckish and look at it or let's remove all of our console
logs and network like this.
And now lets family say buttons like it's slightly like these you know what spam they say about and
so Leglise and you can see I have been redirect that and I sent multiple requests they're going to hear
here.
The first one is all sex at school the Save Our book pause and the dinner and every request after you
can see here is four hundred twenty two and the response is block is saving the saving blood is saving
Blug is saving here.
And when you check your so you have a year's warning that's fine.
But we are redirected the year and when we go up does this Blake just wanna block posts refresh one
block easier.
So let's one more time.
Let's go back to a block reate book editor.
And let's end these multiple requests so it's clear Konsole network and let's say multiple times like
it is now and we can still say Mulvany chigger Consolo you will see should be update.
So I'm calling my save from our update page.
So look editor of The Page networked up our E-Class.
JS What about successful and every request.
After is not successful.
OK let's verify one more time lapse.
There should be just one more so to block those.
Yes.
OK so let's verify our functionality in our calling leaders and the recapitalise.
So what we're doing here let's start from our blog page.
So I look at it.
But if we are creating book post we are sending a request but before that we are getting a look these
are just randomly generated four digit number.
We are providing this look Id to our create a book function.
So in essence in the dodgiest we are calling these they're getting our big data look Id and they are
providing is looked at as a great parameter.
Then we are sending requests to our server to the block.
We are getting it look at it from a very firm and there and we are first checking if a look is not too
busy when it is locked.
Id logged on to busy log this function.
Here it is.
Look I mean I will perform our action so we we'll save our block if luck is busy.
Miller eternity's response state of 4:22 so unsuccessful and we will send a message block is actually
saving legatees for block is getting saved.
All right guys so that's it for his lecture.
Very fire code here.
The blog is very important.
And also this.
Look you need to send as a carry permit there.
So guys naturally for his lecture and inexactitude continue with our update functionality so with our
blog editor update page.
So guys I have to see you in an.