Skip to content

Commit

Permalink
Support async await
Browse files Browse the repository at this point in the history
  • Loading branch information
austinksmith committed Sep 23, 2024
1 parent b3514fa commit eaed5bd
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 5 deletions.
2 changes: 1 addition & 1 deletion build/hamsters.node.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion build/hamsters.node.min.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion build/hamsters.web.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion build/hamsters.web.min.js.map

Large diffs are not rendered by default.

9 changes: 8 additions & 1 deletion src/core/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,14 @@ class Data {
*/
prepareWorkerTask(functionBody) {
let functionString = String(functionBody);
return functionString.substring((functionString.indexOf("{") + 1), (functionString.length -1));
let isAsync = functionString.trim().startsWith('async');
functionBody = functionString.substring(functionString.indexOf("{") + 1, functionString.lastIndexOf("}"));
if(isAsync) {
return `(async () => {
${functionBody}
})();`;
}
return functionBody;
}

/**
Expand Down

0 comments on commit eaed5bd

Please sign in to comment.