Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 48 additions & 26 deletions js/blocks/FlowBlocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,44 +202,66 @@ function setupFlowBlocks(activity) {
tur.singer.inDuplicate = false;
tur.singer.duplicateFactor /= factor;

// Check for a race condition
// FIXME: Do something about the race condition
if (logo.connectionStoreLock) {
console.debug("LOCKED");
}
const restoreConnections = () => {
if (logo.connectionStoreLock) {
setTimeout(restoreConnections, 10);
return;
}

logo.connectionStoreLock = true;
logo.connectionStoreLock = true;

// The last turtle should restore the broken connections
if (__lookForOtherTurtles(blk, turtle) === null) {
const n = logo.connectionStore[turtle][blk].length;
for (let i = 0; i < n; i++) {
const obj = logo.connectionStore[turtle][blk].pop();
activity.blocks.blockList[obj[0]].connections[obj[1]] = obj[2];
if (obj[2] != null) {
activity.blocks.blockList[obj[2]].connections[0] = obj[0];
// The last turtle should restore the broken connections
if (__lookForOtherTurtles(blk, turtle) === null) {
const n = logo.connectionStore[turtle][blk].length;
for (let i = 0; i < n; i++) {
const obj = logo.connectionStore[turtle][blk].pop();
activity.blocks.blockList[obj[0]].connections[obj[1]] = obj[2];
if (obj[2] != null) {
activity.blocks.blockList[obj[2]].connections[0] = obj[0];
}
}
} else {
delete logo.connectionStore[turtle][blk];
}
} else {
delete logo.connectionStore[turtle][blk];
}

logo.connectionStoreLock = false;
logo.connectionStoreLock = false;
};
restoreConnections();
};

// Set the turtle listener
logo.setTurtleListener(turtle, listenerName, __listener);

// Test for race condition
// FIXME: Do something about the race condition
if (logo.connectionStoreLock) {
console.debug("LOCKED");
}
const setupConnections = () => {
if (logo.connectionStoreLock) {
setTimeout(setupConnections, 10);
return;
}

logo.connectionStoreLock = true;
logo.connectionStoreLock = true;

// Check to see if another turtle has already disconnected these blocks
const otherTurtle = __lookForOtherTurtles(blk, turtle);
// Check to see if another turtle has already disconnected these blocks
const otherTurtle = __lookForOtherTurtles(blk, turtle);
if (otherTurtle != null) {
// Copy the connections and queue the blocks
logo.connectionStore[turtle][blk] = [];
for (let i = logo.connectionStore[otherTurtle][blk].length; i > 0; i--) {
const obj = [
logo.connectionStore[otherTurtle][blk][i - 1][0],
logo.connectionStore[otherTurtle][blk][i - 1][1],
logo.connectionStore[otherTurtle][blk][i - 1][2]
];
logo.connectionStore[turtle][blk].push(obj);
}
} else {
// Disconnect the blocks and queue them (so they don't move)
logo.connectionStore[turtle][blk] = [];
logo.disconnectBlock(blk);
}

logo.connectionStoreLock = false;
};
setupConnections();
if (otherTurtle != null) {
// Copy the connections and queue the blocks
logo.connectionStore[turtle][blk] = [];
Expand Down
74 changes: 49 additions & 25 deletions js/blocks/IntervalsBlocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -822,41 +822,65 @@ function setupIntervalsBlocks(activity) {
tur.singer.inDuplicate = false;
tur.singer.duplicateFactor /= factor;
tur.singer.arpeggio = [];
// Check for a race condition.
// FIXME: Do something about the race condition.

const restoreConnections = () => {
if (logo.connectionStoreLock) {
setTimeout(restoreConnections, 10);
return;
}

logo.connectionStoreLock = true;

// The last turtle should restore the broken connections.
if (__lookForOtherTurtles(blk, turtle) === null) {
const n = logo.connectionStore[turtle][blk].length;
for (let i = 0; i < n; i++) {
const obj = logo.connectionStore[turtle][blk].pop();
activity.blocks.blockList[obj[0]].connections[obj[1]] = obj[2];
if (obj[2] != null) {
activity.blocks.blockList[obj[2]].connections[0] = obj[0];
}
}
} else {
delete logo.connectionStore[turtle][blk];
}
logo.connectionStoreLock = false;
};
restoreConnections();
};

logo.setTurtleListener(turtle, listenerName, __listener);

const setupConnections = () => {
if (logo.connectionStoreLock) {
// eslint-disable-next-line no-console
console.debug("LOCKED");
setTimeout(setupConnections, 10);
return;
}

logo.connectionStoreLock = true;

// The last turtle should restore the broken connections.
if (__lookForOtherTurtles(blk, turtle) === null) {
const n = logo.connectionStore[turtle][blk].length;
for (let i = 0; i < n; i++) {
const obj = logo.connectionStore[turtle][blk].pop();
activity.blocks.blockList[obj[0]].connections[obj[1]] = obj[2];
if (obj[2] != null) {
activity.blocks.blockList[obj[2]].connections[0] = obj[0];
}
// Check to see if another turtle has already disconnected these blocks
const otherTurtle = __lookForOtherTurtles(blk, turtle);
if (otherTurtle != null) {
// Copy the connections and queue the blocks.
logo.connectionStore[turtle][blk] = [];
for (let i = logo.connectionStore[otherTurtle][blk].length; i > 0; i--) {
const obj = [
logo.connectionStore[otherTurtle][blk][i - 1][0],
logo.connectionStore[otherTurtle][blk][i - 1][1],
logo.connectionStore[otherTurtle][blk][i - 1][2]
];
logo.connectionStore[turtle][blk].push(obj);
}
} else {
delete logo.connectionStore[turtle][blk];
// Disconnect the blocks and queue them (so they don't move).
logo.connectionStore[turtle][blk] = [];
logo.disconnectBlock(blk);
}

logo.connectionStoreLock = false;
};

logo.setTurtleListener(turtle, listenerName, __listener);

// Test for race condition.
// FIXME: Do something about the race condition.
if (logo.connectionStoreLock) {
// eslint-disable-next-line no-console
console.debug("LOCKED");
}

logo.connectionStoreLock = true;
setupConnections();

// Check to see if another turtle has already disconnected these blocks
const otherTurtle = __lookForOtherTurtles(blk, turtle);
Expand Down
Loading