Fix the remaining issues for MAGN-3785

@lukechurch

This submission fixes some remaining issues with the case in MAGN-3785:
1). Concurrency issues: sometimes multiple threads are accessing the same queue: Promises in IdlePromise,  with one thread to enqueue and another thread to dequeue. This submission adds a lock to prevent write access to the same data.

2). Transaction issues:
     2.1). The old transaction is not disposed before a new transaction of the same name is created. This submission disposes the old transaction immediately before the new transaction is created.
     2.2). In the idle task, the transaction is not committed after the task is done. This causes the transaction's status to be RolledBack later. This submission commits the transaction in the idle task when the document is regenerated.
the interleave logic here is odd.

If (x == null || y)
 if (x != null)
  Do something

I think there's a simplifying transform that makes it easier to read. Follow on PR