Skip to content

Instantly share code, notes, and snippets.

@Streeterxs
Created December 16, 2019 18:35
Show Gist options
  • Save Streeterxs/f609acd2e3a6a3b5d4bb8fdf71841726 to your computer and use it in GitHub Desktop.
Save Streeterxs/f609acd2e3a6a3b5d4bb8fdf71841726 to your computer and use it in GitHub Desktop.
/// <reference lib="webworker" />
addEventListener('message', ({ data }) => {
const response = `worker response to ${data.lista}`;
const objMessageReturn = {
value: data.lista[0],
halfDown: null,
halfUp: null
};
if (data.lista.length > 1) {
data.lista.splice(0, 1);
const halfLength = Math.ceil(data.lista.length / 2);
if (data.lista.length > 1) {
const halfDown = data.lista.slice(0, halfLength);
const halfUp = data.lista.slice(halfLength, data.lista.length);
objMessageReturn.halfDown = halfDown;
objMessageReturn.halfUp = halfUp;
} else {
data.halfDown = data.lista;
}
}
postMessage(objMessageReturn);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment