Skip to content

Setting DB inside forEach calls forEach  #241

@Herobrine643928

Description

@Herobrine643928

Describe the bug
Calling forEach on a database and setting/updating the database that was called for the forEach loop causes the forEach loop to repeat until watchdog terminates the code. I assume this is because it adds a new element to the database, and the forEach then sees that as a new element and calls itself again.
Expected behavior
The forEach should terminate- the workaround for this is to push all altered database elements to temporary storage, then setting each element outside of the loop. If this is how it is meant to be used, please let me know.
Screenshots
Using the following, triggered from a chat command:

const Db = new JaylyDB('Testing');
Db.set('Test', 0);
Db.forEach(variable => {
	console.warn(variable);
	variable++;
	Db.set('Test', variable);
})

image

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions