Handling asynchronous function with webworker and promise
I try to handle the return of promise in order to get a blocking behavior when I call the asyncFunc defined in the code snippet below. In this function, I am using a webworker.
I am not an expert in javascript and the concept of promise is new for me. I tried to define an asyncFunc function into the block of my code.
If I call this function after, I should normally have the code inside asyncFunc completely executed (but I am not sure).
The goal is to draw in a canvas (which is currently representing the gameboard) once webworker has received the array to draw(HitCurrentvariable) here, i.e in a synchronous way (drawing function is performed by displayCurrentHit(HitCurrent);)
else if (mode == 'computer') {
// Call asynchronous function with promise
function asyncFunc(HitCurrent) {
// Return promise
return new Promise( resolve => {
// Creation of webworker
let firstWorker = new Worker(workerScript);
firstWorker.onmessage = function (event) {
resolve(event.data);
}
// Post current copy of HitCurrent, i.e HitCurrent
firstWorker.postMessage([HitCurrent, HitCurrent.playerCurrent, maxNodes]);
}).then(({result}) => {
// Get back game board of webworker
HitCurrent = result.HitResult;
// Get back suggested hit computed by webworker
[a,b] = HitCurrent.coordPlayable;
console.log('Into promise : coordPlayable : (a,b) = ',a,b);
// Drawing all lines from suggested hit (in 8 directions)
for (k = 0; k < 8; k++) {
exploreHitLine(HitCurrent, a, b, k, 'drawing');
}
// Remove playable hits
cleanHits('playable', HitCurrent);
// Display current game
displayCurrentHit(HitCurrent);
// Up to there, first computer hit is good
// and game board is well drawn
alert('Stop just after displayCurrentHit');
})
}
// Call asyncFunc : blocking ???
asyncFunc(HitCurrent).then(console.log('Call async function'));
// Prove asynchronuous of asyncFunc call
alert('after asynFunc().then');
}
The call of asyncFunc is not blocking . If someone could give a method to display current gameboard in a synchronous way using Promise concept ?
Regards
javascript asynchronous promise blocking
|
show 8 more comments
I try to handle the return of promise in order to get a blocking behavior when I call the asyncFunc defined in the code snippet below. In this function, I am using a webworker.
I am not an expert in javascript and the concept of promise is new for me. I tried to define an asyncFunc function into the block of my code.
If I call this function after, I should normally have the code inside asyncFunc completely executed (but I am not sure).
The goal is to draw in a canvas (which is currently representing the gameboard) once webworker has received the array to draw(HitCurrentvariable) here, i.e in a synchronous way (drawing function is performed by displayCurrentHit(HitCurrent);)
else if (mode == 'computer') {
// Call asynchronous function with promise
function asyncFunc(HitCurrent) {
// Return promise
return new Promise( resolve => {
// Creation of webworker
let firstWorker = new Worker(workerScript);
firstWorker.onmessage = function (event) {
resolve(event.data);
}
// Post current copy of HitCurrent, i.e HitCurrent
firstWorker.postMessage([HitCurrent, HitCurrent.playerCurrent, maxNodes]);
}).then(({result}) => {
// Get back game board of webworker
HitCurrent = result.HitResult;
// Get back suggested hit computed by webworker
[a,b] = HitCurrent.coordPlayable;
console.log('Into promise : coordPlayable : (a,b) = ',a,b);
// Drawing all lines from suggested hit (in 8 directions)
for (k = 0; k < 8; k++) {
exploreHitLine(HitCurrent, a, b, k, 'drawing');
}
// Remove playable hits
cleanHits('playable', HitCurrent);
// Display current game
displayCurrentHit(HitCurrent);
// Up to there, first computer hit is good
// and game board is well drawn
alert('Stop just after displayCurrentHit');
})
}
// Call asyncFunc : blocking ???
asyncFunc(HitCurrent).then(console.log('Call async function'));
// Prove asynchronuous of asyncFunc call
alert('after asynFunc().then');
}
The call of asyncFunc is not blocking . If someone could give a method to display current gameboard in a synchronous way using Promise concept ?
Regards
javascript asynchronous promise blocking
3
You might consider using consistent indentation when writing code - it'll make read and debugging it much easier, not only for potential answerers, but for you as well, when we can all see the{}blocks and their nesting level at a glance.
– CertainPerformance
Dec 30 '18 at 23:10
@CertainPerformance . Sorry, I only know the shortcut CTRL+K to indent code.
– youpilat13
Dec 30 '18 at 23:13
3
asyncfunctions do not block.
– trincot
Dec 30 '18 at 23:15
1
.then(console.log('Call async function'))then expects a function to call as argument. What you do is callingconsole.log('Call async function')immediately and passing the result (undefined) to.then()
– Thomas
Dec 30 '18 at 23:28
1
Are you really instantiating a new webworker at every game action? And without ever destroying it?
– Kaiido
Dec 30 '18 at 23:53
|
show 8 more comments
I try to handle the return of promise in order to get a blocking behavior when I call the asyncFunc defined in the code snippet below. In this function, I am using a webworker.
I am not an expert in javascript and the concept of promise is new for me. I tried to define an asyncFunc function into the block of my code.
If I call this function after, I should normally have the code inside asyncFunc completely executed (but I am not sure).
The goal is to draw in a canvas (which is currently representing the gameboard) once webworker has received the array to draw(HitCurrentvariable) here, i.e in a synchronous way (drawing function is performed by displayCurrentHit(HitCurrent);)
else if (mode == 'computer') {
// Call asynchronous function with promise
function asyncFunc(HitCurrent) {
// Return promise
return new Promise( resolve => {
// Creation of webworker
let firstWorker = new Worker(workerScript);
firstWorker.onmessage = function (event) {
resolve(event.data);
}
// Post current copy of HitCurrent, i.e HitCurrent
firstWorker.postMessage([HitCurrent, HitCurrent.playerCurrent, maxNodes]);
}).then(({result}) => {
// Get back game board of webworker
HitCurrent = result.HitResult;
// Get back suggested hit computed by webworker
[a,b] = HitCurrent.coordPlayable;
console.log('Into promise : coordPlayable : (a,b) = ',a,b);
// Drawing all lines from suggested hit (in 8 directions)
for (k = 0; k < 8; k++) {
exploreHitLine(HitCurrent, a, b, k, 'drawing');
}
// Remove playable hits
cleanHits('playable', HitCurrent);
// Display current game
displayCurrentHit(HitCurrent);
// Up to there, first computer hit is good
// and game board is well drawn
alert('Stop just after displayCurrentHit');
})
}
// Call asyncFunc : blocking ???
asyncFunc(HitCurrent).then(console.log('Call async function'));
// Prove asynchronuous of asyncFunc call
alert('after asynFunc().then');
}
The call of asyncFunc is not blocking . If someone could give a method to display current gameboard in a synchronous way using Promise concept ?
Regards
javascript asynchronous promise blocking
I try to handle the return of promise in order to get a blocking behavior when I call the asyncFunc defined in the code snippet below. In this function, I am using a webworker.
I am not an expert in javascript and the concept of promise is new for me. I tried to define an asyncFunc function into the block of my code.
If I call this function after, I should normally have the code inside asyncFunc completely executed (but I am not sure).
The goal is to draw in a canvas (which is currently representing the gameboard) once webworker has received the array to draw(HitCurrentvariable) here, i.e in a synchronous way (drawing function is performed by displayCurrentHit(HitCurrent);)
else if (mode == 'computer') {
// Call asynchronous function with promise
function asyncFunc(HitCurrent) {
// Return promise
return new Promise( resolve => {
// Creation of webworker
let firstWorker = new Worker(workerScript);
firstWorker.onmessage = function (event) {
resolve(event.data);
}
// Post current copy of HitCurrent, i.e HitCurrent
firstWorker.postMessage([HitCurrent, HitCurrent.playerCurrent, maxNodes]);
}).then(({result}) => {
// Get back game board of webworker
HitCurrent = result.HitResult;
// Get back suggested hit computed by webworker
[a,b] = HitCurrent.coordPlayable;
console.log('Into promise : coordPlayable : (a,b) = ',a,b);
// Drawing all lines from suggested hit (in 8 directions)
for (k = 0; k < 8; k++) {
exploreHitLine(HitCurrent, a, b, k, 'drawing');
}
// Remove playable hits
cleanHits('playable', HitCurrent);
// Display current game
displayCurrentHit(HitCurrent);
// Up to there, first computer hit is good
// and game board is well drawn
alert('Stop just after displayCurrentHit');
})
}
// Call asyncFunc : blocking ???
asyncFunc(HitCurrent).then(console.log('Call async function'));
// Prove asynchronuous of asyncFunc call
alert('after asynFunc().then');
}
The call of asyncFunc is not blocking . If someone could give a method to display current gameboard in a synchronous way using Promise concept ?
Regards
javascript asynchronous promise blocking
javascript asynchronous promise blocking
edited Jan 4 at 2:27
youpilat13
asked Dec 30 '18 at 23:09
youpilat13youpilat13
10311440
10311440
3
You might consider using consistent indentation when writing code - it'll make read and debugging it much easier, not only for potential answerers, but for you as well, when we can all see the{}blocks and their nesting level at a glance.
– CertainPerformance
Dec 30 '18 at 23:10
@CertainPerformance . Sorry, I only know the shortcut CTRL+K to indent code.
– youpilat13
Dec 30 '18 at 23:13
3
asyncfunctions do not block.
– trincot
Dec 30 '18 at 23:15
1
.then(console.log('Call async function'))then expects a function to call as argument. What you do is callingconsole.log('Call async function')immediately and passing the result (undefined) to.then()
– Thomas
Dec 30 '18 at 23:28
1
Are you really instantiating a new webworker at every game action? And without ever destroying it?
– Kaiido
Dec 30 '18 at 23:53
|
show 8 more comments
3
You might consider using consistent indentation when writing code - it'll make read and debugging it much easier, not only for potential answerers, but for you as well, when we can all see the{}blocks and their nesting level at a glance.
– CertainPerformance
Dec 30 '18 at 23:10
@CertainPerformance . Sorry, I only know the shortcut CTRL+K to indent code.
– youpilat13
Dec 30 '18 at 23:13
3
asyncfunctions do not block.
– trincot
Dec 30 '18 at 23:15
1
.then(console.log('Call async function'))then expects a function to call as argument. What you do is callingconsole.log('Call async function')immediately and passing the result (undefined) to.then()
– Thomas
Dec 30 '18 at 23:28
1
Are you really instantiating a new webworker at every game action? And without ever destroying it?
– Kaiido
Dec 30 '18 at 23:53
3
3
You might consider using consistent indentation when writing code - it'll make read and debugging it much easier, not only for potential answerers, but for you as well, when we can all see the
{ } blocks and their nesting level at a glance.– CertainPerformance
Dec 30 '18 at 23:10
You might consider using consistent indentation when writing code - it'll make read and debugging it much easier, not only for potential answerers, but for you as well, when we can all see the
{ } blocks and their nesting level at a glance.– CertainPerformance
Dec 30 '18 at 23:10
@CertainPerformance . Sorry, I only know the shortcut CTRL+K to indent code.
– youpilat13
Dec 30 '18 at 23:13
@CertainPerformance . Sorry, I only know the shortcut CTRL+K to indent code.
– youpilat13
Dec 30 '18 at 23:13
3
3
async functions do not block.– trincot
Dec 30 '18 at 23:15
async functions do not block.– trincot
Dec 30 '18 at 23:15
1
1
.then(console.log('Call async function')) then expects a function to call as argument. What you do is calling console.log('Call async function') immediately and passing the result (undefined) to .then()– Thomas
Dec 30 '18 at 23:28
.then(console.log('Call async function')) then expects a function to call as argument. What you do is calling console.log('Call async function') immediately and passing the result (undefined) to .then()– Thomas
Dec 30 '18 at 23:28
1
1
Are you really instantiating a new webworker at every game action? And without ever destroying it?
– Kaiido
Dec 30 '18 at 23:53
Are you really instantiating a new webworker at every game action? And without ever destroying it?
– Kaiido
Dec 30 '18 at 23:53
|
show 8 more comments
1 Answer
1
active
oldest
votes
You have a wrong syntax resolving your promise.
.then accepts a function callback within, called when the promise will be resolved.
So in your case this code:
// Call asyncFunc : blocking ???
asyncFunc(HitCurrent).then(console.log('Call async function'));
// Prove asynchronuous of asyncFunc call
alert('after asynFunc().then');
Should be:
asyncFunc(HitCurrent).then(() => alert('after asynFunc()'));
Instead in order to write your code in a "sync way", you can use async/await in this way:
function asyncFunc(HitCurrent) {
// Return promise
return new Promise(resolve => {
setTimeout(() => resolve('finished'), 1000);
}).then(data => {
alert('promise resolved:' + data);
})
}
(async () => {
await asyncFunc();
alert('after asynFunc().then');
})();So you create an async function which awaits for the resolution of your promise and then alerts the values.
ok thanks ! I am going to try your solution. But why does -@Patrick Roberts told me that it was impossible in my case ? Regards
– youpilat13
Dec 30 '18 at 23:42
I think that he understood that you don't want simply to write your code like if it appears sync, but you want really that the code will be executed sync at OS level. But maybe asking him would be the best thing to do :)
– quirimmo
Dec 30 '18 at 23:45
Ok it works as expected ! really thanks. If I have well understood, we can circumevent the issue by using(async)and awaitasyncFunc: so the part(async () => { await asyncFunc(); alert('after asynFunc().then'); })();is blocking, I mean, waiting the execution of allasyncFuncfunction, isn't it ?
– youpilat13
Dec 30 '18 at 23:53
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53982173%2fhandling-asynchronous-function-with-webworker-and-promise%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
You have a wrong syntax resolving your promise.
.then accepts a function callback within, called when the promise will be resolved.
So in your case this code:
// Call asyncFunc : blocking ???
asyncFunc(HitCurrent).then(console.log('Call async function'));
// Prove asynchronuous of asyncFunc call
alert('after asynFunc().then');
Should be:
asyncFunc(HitCurrent).then(() => alert('after asynFunc()'));
Instead in order to write your code in a "sync way", you can use async/await in this way:
function asyncFunc(HitCurrent) {
// Return promise
return new Promise(resolve => {
setTimeout(() => resolve('finished'), 1000);
}).then(data => {
alert('promise resolved:' + data);
})
}
(async () => {
await asyncFunc();
alert('after asynFunc().then');
})();So you create an async function which awaits for the resolution of your promise and then alerts the values.
ok thanks ! I am going to try your solution. But why does -@Patrick Roberts told me that it was impossible in my case ? Regards
– youpilat13
Dec 30 '18 at 23:42
I think that he understood that you don't want simply to write your code like if it appears sync, but you want really that the code will be executed sync at OS level. But maybe asking him would be the best thing to do :)
– quirimmo
Dec 30 '18 at 23:45
Ok it works as expected ! really thanks. If I have well understood, we can circumevent the issue by using(async)and awaitasyncFunc: so the part(async () => { await asyncFunc(); alert('after asynFunc().then'); })();is blocking, I mean, waiting the execution of allasyncFuncfunction, isn't it ?
– youpilat13
Dec 30 '18 at 23:53
add a comment |
You have a wrong syntax resolving your promise.
.then accepts a function callback within, called when the promise will be resolved.
So in your case this code:
// Call asyncFunc : blocking ???
asyncFunc(HitCurrent).then(console.log('Call async function'));
// Prove asynchronuous of asyncFunc call
alert('after asynFunc().then');
Should be:
asyncFunc(HitCurrent).then(() => alert('after asynFunc()'));
Instead in order to write your code in a "sync way", you can use async/await in this way:
function asyncFunc(HitCurrent) {
// Return promise
return new Promise(resolve => {
setTimeout(() => resolve('finished'), 1000);
}).then(data => {
alert('promise resolved:' + data);
})
}
(async () => {
await asyncFunc();
alert('after asynFunc().then');
})();So you create an async function which awaits for the resolution of your promise and then alerts the values.
ok thanks ! I am going to try your solution. But why does -@Patrick Roberts told me that it was impossible in my case ? Regards
– youpilat13
Dec 30 '18 at 23:42
I think that he understood that you don't want simply to write your code like if it appears sync, but you want really that the code will be executed sync at OS level. But maybe asking him would be the best thing to do :)
– quirimmo
Dec 30 '18 at 23:45
Ok it works as expected ! really thanks. If I have well understood, we can circumevent the issue by using(async)and awaitasyncFunc: so the part(async () => { await asyncFunc(); alert('after asynFunc().then'); })();is blocking, I mean, waiting the execution of allasyncFuncfunction, isn't it ?
– youpilat13
Dec 30 '18 at 23:53
add a comment |
You have a wrong syntax resolving your promise.
.then accepts a function callback within, called when the promise will be resolved.
So in your case this code:
// Call asyncFunc : blocking ???
asyncFunc(HitCurrent).then(console.log('Call async function'));
// Prove asynchronuous of asyncFunc call
alert('after asynFunc().then');
Should be:
asyncFunc(HitCurrent).then(() => alert('after asynFunc()'));
Instead in order to write your code in a "sync way", you can use async/await in this way:
function asyncFunc(HitCurrent) {
// Return promise
return new Promise(resolve => {
setTimeout(() => resolve('finished'), 1000);
}).then(data => {
alert('promise resolved:' + data);
})
}
(async () => {
await asyncFunc();
alert('after asynFunc().then');
})();So you create an async function which awaits for the resolution of your promise and then alerts the values.
You have a wrong syntax resolving your promise.
.then accepts a function callback within, called when the promise will be resolved.
So in your case this code:
// Call asyncFunc : blocking ???
asyncFunc(HitCurrent).then(console.log('Call async function'));
// Prove asynchronuous of asyncFunc call
alert('after asynFunc().then');
Should be:
asyncFunc(HitCurrent).then(() => alert('after asynFunc()'));
Instead in order to write your code in a "sync way", you can use async/await in this way:
function asyncFunc(HitCurrent) {
// Return promise
return new Promise(resolve => {
setTimeout(() => resolve('finished'), 1000);
}).then(data => {
alert('promise resolved:' + data);
})
}
(async () => {
await asyncFunc();
alert('after asynFunc().then');
})();So you create an async function which awaits for the resolution of your promise and then alerts the values.
function asyncFunc(HitCurrent) {
// Return promise
return new Promise(resolve => {
setTimeout(() => resolve('finished'), 1000);
}).then(data => {
alert('promise resolved:' + data);
})
}
(async () => {
await asyncFunc();
alert('after asynFunc().then');
})();function asyncFunc(HitCurrent) {
// Return promise
return new Promise(resolve => {
setTimeout(() => resolve('finished'), 1000);
}).then(data => {
alert('promise resolved:' + data);
})
}
(async () => {
await asyncFunc();
alert('after asynFunc().then');
})();edited Dec 30 '18 at 23:47
answered Dec 30 '18 at 23:38
quirimmoquirimmo
7,38611331
7,38611331
ok thanks ! I am going to try your solution. But why does -@Patrick Roberts told me that it was impossible in my case ? Regards
– youpilat13
Dec 30 '18 at 23:42
I think that he understood that you don't want simply to write your code like if it appears sync, but you want really that the code will be executed sync at OS level. But maybe asking him would be the best thing to do :)
– quirimmo
Dec 30 '18 at 23:45
Ok it works as expected ! really thanks. If I have well understood, we can circumevent the issue by using(async)and awaitasyncFunc: so the part(async () => { await asyncFunc(); alert('after asynFunc().then'); })();is blocking, I mean, waiting the execution of allasyncFuncfunction, isn't it ?
– youpilat13
Dec 30 '18 at 23:53
add a comment |
ok thanks ! I am going to try your solution. But why does -@Patrick Roberts told me that it was impossible in my case ? Regards
– youpilat13
Dec 30 '18 at 23:42
I think that he understood that you don't want simply to write your code like if it appears sync, but you want really that the code will be executed sync at OS level. But maybe asking him would be the best thing to do :)
– quirimmo
Dec 30 '18 at 23:45
Ok it works as expected ! really thanks. If I have well understood, we can circumevent the issue by using(async)and awaitasyncFunc: so the part(async () => { await asyncFunc(); alert('after asynFunc().then'); })();is blocking, I mean, waiting the execution of allasyncFuncfunction, isn't it ?
– youpilat13
Dec 30 '18 at 23:53
ok thanks ! I am going to try your solution. But why does -@Patrick Roberts told me that it was impossible in my case ? Regards
– youpilat13
Dec 30 '18 at 23:42
ok thanks ! I am going to try your solution. But why does -@Patrick Roberts told me that it was impossible in my case ? Regards
– youpilat13
Dec 30 '18 at 23:42
I think that he understood that you don't want simply to write your code like if it appears sync, but you want really that the code will be executed sync at OS level. But maybe asking him would be the best thing to do :)
– quirimmo
Dec 30 '18 at 23:45
I think that he understood that you don't want simply to write your code like if it appears sync, but you want really that the code will be executed sync at OS level. But maybe asking him would be the best thing to do :)
– quirimmo
Dec 30 '18 at 23:45
Ok it works as expected ! really thanks. If I have well understood, we can circumevent the issue by using
(async) and await asyncFunc : so the part (async () => { await asyncFunc(); alert('after asynFunc().then'); })();is blocking, I mean, waiting the execution of all asyncFuncfunction, isn't it ?– youpilat13
Dec 30 '18 at 23:53
Ok it works as expected ! really thanks. If I have well understood, we can circumevent the issue by using
(async) and await asyncFunc : so the part (async () => { await asyncFunc(); alert('after asynFunc().then'); })();is blocking, I mean, waiting the execution of all asyncFuncfunction, isn't it ?– youpilat13
Dec 30 '18 at 23:53
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53982173%2fhandling-asynchronous-function-with-webworker-and-promise%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
3
You might consider using consistent indentation when writing code - it'll make read and debugging it much easier, not only for potential answerers, but for you as well, when we can all see the
{}blocks and their nesting level at a glance.– CertainPerformance
Dec 30 '18 at 23:10
@CertainPerformance . Sorry, I only know the shortcut CTRL+K to indent code.
– youpilat13
Dec 30 '18 at 23:13
3
asyncfunctions do not block.– trincot
Dec 30 '18 at 23:15
1
.then(console.log('Call async function'))then expects a function to call as argument. What you do is callingconsole.log('Call async function')immediately and passing the result (undefined) to.then()– Thomas
Dec 30 '18 at 23:28
1
Are you really instantiating a new webworker at every game action? And without ever destroying it?
– Kaiido
Dec 30 '18 at 23:53