I am making a game with rxjs.
When I update value on behaviour subject using the next method I cant await until all the subscribers played, for example finished their animations.
Is it possible to await until all subscribers played?
I have tried but wasn't able to find any info on that. Please help.
data.next("some data needed for animation");
somwhere
data.subscribe((response)=>{
const allAnimationResponse = await await gsap.to(pixiSprite, {duration: 1, x: 100});
if(allAnimationResponse){
// you can access response and allAnimationResponse
// execute next line
}
})
Related
I am using the pupperteer library for my bot and I would like to perform some operations in parallel.
In many articles, it is advised to use this syntax :
await Promise.all(array.map(async data => //..some operations))
I've tested this on several operations and it works but when I embed the code below in my .map promise
await page.goto(..
It did not work during Operation Promise and it considers this to be a synchronous operation.
I would like to know why it reacts like this?
I believe your error comes from the fact that you're using the same page object.
The following should work:
const currentPage = browser.pages().then(allPages => allPages[0]);
const anotherPage = await browser.newPage();
const bothPages = [currentPage, anotherPage];
await Promise.all(
bothPages.map(page => page.goto("https://stackoverflow.com"))
);
I am trying to get the data stored in my ObjectStore and I want this synchronously. So instead of using onsuccess I want to use await / async.
I have implemented this below code but somehow its not returning me the data.
async function viewNotes() {
const tx = db.transaction("personal_notes","readonly")
const pNotes = tx.objectStore("personal_notes")
const items = await db.transaction("personal_notes").objectStore("personal_notes").getAllKeys()
console.log("And the Items are ", items.result)
let NotesHere = await pNotes.getAll().onsuccess
console.log("Ans this are the logs", NotesHere)
}
Neither I am getting the data through items.result nor from NotesHere.
When I view from debug mode, items's readyState is still in pending even after using await.
What am I missing ?
The IndexedDB API does not natively support async/await. You need to either manually wrap the event handlers in promises, or (much better solution) use a library like https://github.com/jakearchibald/idb that does it for you.
I don't know why I'm not getting notification events from sails models from model.publish().
In pre-1.x sailsjs, similar client-side code had worked and I would get every event when records are created, updated or deleted. So, I must be misunderstanding something.
How do I subscribe to all events for any records from CRUD operations?
On the server side, I have Job.js and JobController.js.
In Job.js model, this test just creates a new record every 10 secs:
test: async function(dataset) {
let count = 0;
setInterval(async function() {
count++;
let newjob = {
dataset: dataset,
state: 'delayed',
name: "job name "+count
};
let job = await Job.create(newjob).fetch()
sails.log.info('created test job: ',JSON.stringify(job));
Job.publish([job.id],job);
},10000);
}
In JobController.js, called by the client and starts the test rolling:
submittest: async function(req,res) {
let dataset = await Dataset.Get({});
await Job.test(dataset[0].id);
return res.ok({status:'ok'});
}
In the client test.html, io.socket.get operations are successful, but I never see an event:
...
<script>
io.socket.get('/job', function(body, JWR) {
console.log('and with status code: ', JWR.statusCode);
setTimeout(function() {
io.socket.get('/job/submittest', function (body,JWR) {
io.socket.on('job', function(msg) {
console.log("job event",msg); // not getting here. why?
});
});
},2000)
});
</script>
This all runs fine but the problem is, no events are seen from the client side. Why? Am I not subscribed to events with the initial io.socket.get('/job')?
Essentially, what is happening here, is you are shouting into an empty box about a new record in your model, but no one is listening to you in that empty box.
In other words, you need to subscribe the socket connection to the model updates.
See: https://sailsjs.com/documentation/reference/web-sockets/resourceful-pub-sub/subscribe
Also, checkout the answer to this question for a quick how to.
I have a couple of questions about the example that shows how to start a proactive dialog:
using (var scope = DialogModule.BeginLifetimeScope(Conversation.Container, activity))
{
var botData = scope.Resolve<IBotData>();
await botData.LoadAsync(token);
var task = scope.Resolve<IDialogTask>();
var interruption = dialog.Void<T, IMessageActivity>();
task.Call(interruption, null);
await task.PollAsync(token);
await botData.FlushAsync(token);
}
What is the point of calling dialog.Void?
How can I use a ResumeAfter? If i add a ResumeAfter handler and await the result i get an error indicating it was expecting Call and got Poll
Is this code supposed to block until the dialog is complete? Because it does not
How can I push a proactive dialog and await its result?
I want to display a processing message to the user while the Bot is performing some heavy data retrieval task.
var leadRetrievalTask = Task.Run(() =>
{
msg = LeadsManager.getTopLeads(authRes);
});
await context.PostAsync("Retrieving Top Leads data..."); //should display processing message`enter code here`
await leadRetrievalTask;
await context.PostAsync(msg); //should display result
context.Wait(MessageReceived);
But both the message and results are getting displayed together. Any way to achieve this?
We don't have yet, but are planning (for channels that support it) support for the "Typing..." message some channels support.
How long is the task? Are you saying they're not posting separately?