OK, here’s my simplified use case:
I have a list of email addresses, I looping through them and checking if they exist. If they don’t, then I create them on the server, but then in the same function I need to create a document and set a field as the created user’s ID. How can I accomplish this?
Accounts.createUser only returns the _id on the server, so on the client it’s undefined. I can use a callback, but the rest will have moved on using ‘undefined’, which doesn’t help anything.
Is this a job for promises? Futures? I honestly don’t really know what those are, but that they help with asynchronous functions, which I think is part of the issue here, right?
Because this function is run infrequently, it would even be OK if the whole script stopped and waited for the _id to return from the server, as it’s unlikely many new users will be created.
These are solutions I’ve looked at, which don’t work because I want to get the _id in the same function, and not accomplish some separate functionality when a new user is created: