Function withLockFactory