Refer https://www.netlify.com/blog/2019/01/16/redirect-rules-for-all-how-to-configure-redirects-for-your-static-site/ to add redirects to your SPA
Add _redirects file in your build folder. Example: build, dist, public. And add /* /index.html 200
| #!/bin/bash | |
| # Set the branch name as the first argument passed to the script | |
| branch_name=$1 | |
| # Cancel the skip-worktree changes for all files | |
| git ls-files -v | grep ^S | cut -c 3- | xargs git update-index --no-skip-worktree | |
| # Stash all files | |
| git stash save --keep-index --include-untracked "Stashing skip-worktree files" |
| #!/bin/sh | |
| branch=$1 | |
| if [ ! -z "$1" ] | |
| then | |
| git branch -D $branch | |
| git push -d origin $branch | |
| else | |
| echo "Branch name is not specified" |
Refer https://www.netlify.com/blog/2019/01/16/redirect-rules-for-all-how-to-configure-redirects-for-your-static-site/ to add redirects to your SPA
Add _redirects file in your build folder. Example: build, dist, public. And add /* /index.html 200
| // workerPool.js | |
| // Worker Thread pool | |
| const {Worker, parentPort, MessageChannel} = require('worker_threads') | |
| class WorkerPool { | |
| constructor(size, worker) { | |
| this.size = size | |
| this.worker = worker | |
| this.pool = [] |
| // main.js | |
| const {Worker, parentPort, MessageChannel} = require('worker_threads') | |
| const worker = new Worker('./worker.js') | |
| const messageChannel = new MessageChannel() | |
| // As you can see there are two parameters passed in `postMessage` | |
| worker.postMessage({yourPort: messageChannel.port1}, [messageChannel.port1]) |
| const { MessageChannel } = require('worker_threads') | |
| const {port1, port2} = new MessageChannel() | |
| port1.once('message', (msg) => { | |
| console.log(msg) | |
| }) | |
| port2.postMessage({msg: "hello world"}) |
| const {Worker, isMainThread, parentPort, workerData} = require('worker_threads') | |
| // Returns if the script runs in main thread of in worker | |
| if (isMainThread) { | |
| const arr = [[1, 10],[2, 15],[3, 21],[4, 25],[5, 86]] | |
| for (const ele of arr) { | |
| const worker = new Worker(__filename, {workerData: {a: ele[0], b: ele[1]}}) | |
| worker.on('message', (result) => { | |
| console.log(`The sum of ${ele[0]} and ${ele[1]} is ${result}`) |
| // index.js | |
| const {Worker, isMainThread, parentPort, workerData} = require('worker_threads') | |
| const worker = new Worker("./worker.js", {workerData: {a: 5, b: 10}}) | |
| worker.once('message', (result) => { | |
| console.log('The sum is', result) | |
| }) |
| // Function to fetch Github info of a user. | |
| const fetchGithubInfo = async (url) => { | |
| console.log(`Fetching ${url}`) | |
| const githubInfo = await axios(url) // API call to get user info from Github. | |
| return { | |
| name: githubInfo.data.name, | |
| bio: githubInfo.data.bio, | |
| repos: githubInfo.data.public_repos | |
| } | |
| } |
| // Async function to send mail to a list of users. | |
| const sendMailForUsers = async (users) => { | |
| const usersLength = users.length | |
| for (let i = 0; i < usersLength; i += 100) { | |
| const requests = users.slice(i, i + 100).map((user) => { // The batch size is 100. We are processing in a set of 100 users. | |
| return triggerMailForUser(user) // Async function to send the mail. | |
| .catch(e => console.log(`Error in sending email for ${user} - ${e}`)) // Catch the error if something goes wrong. So that it won't block the loop. | |
| }) | |