Tengo esta función en mi vista de Backbone para crear un nuevo objeto a través de una API en el backend:
// *** called when remote hardware signal triggered createConference: function () { var self = this; console.log("ScheduleLocationArea.js - createConference() ") const startTime = performance.now(); this.sysLocation.create().then((response) => { self.model.collection.add(response); }); const duration = performance.now() - startTime; console.log(`PERFORMANACE CHECK: ScheduleLocationArea.js - the function createConference() took ${duration}ms`); },Está llamando a esta función:
// called from within createConference async create() { console.log("Location.js - create() ") const startTime = performance.now(); return await this.sync('create', this, { url: this.create.url(this.id) }, { silent: true }); const duration = performance.now() - startTime; console.log(`PERFORMANACE CHECK: Location.js - the function create() took ${duration}ms`); },Como puede ver, estoy tratando de comprobar los problemas de rendimiento.
Pero por alguna razón que no puedo entender, no está finalizando la función create() . Nunca veo la PERFORMANACE CHECK para esa función.
Aquí está la salida de mi consola:
ScheduleLocationArea.js - createConference() Location.js:22 Location.js - create() ScheduleLocationArea.js:269 PERFORMANACE CHECK: ScheduleLocationArea.js - the function createConference() took 1.7000000476837158msEl navegador escribe todos los mensajes de la consola anteriores muy rápido.
Y aunque dice que solo tardó 1,7 ms... en realidad tarda unos 3 segundos.
Así que no puedo entender por qué está tardando tanto y por qué no está escribiendo los números de rendimiento para la función create() .
¿Hay algo que estoy haciendo mal?
¡Gracias!
Está regresando de su función antes de llamar a console.log en su primer fragmento. Cualquier código que sigue a una declaración de devolución no se ejecuta:
// called from within createConference async create() { console.log("Location.js - create() ") const startTime = performance.now(); return await this.sync('create', this, { url: this.create.url(this.id) }, { silent: true }); // this following code never runs as screate(0 has returned already const duration = performance.now() - startTime; console.log(`PERFORMANACE CHECK: Location.js - the function create() took ${duration}ms`); },Cambia tu código de:
// called from within createConference async create() { console.log("Location.js - create() ") const startTime = performance.now(); return await this.sync('create', this, { url: this.create.url(this.id) }, { silent: true }); const duration = performance.now() - startTime; console.log(`PERFORMANACE CHECK: Location.js - the function create() took ${duration}ms`); },a
// called from within createConference async create() { console.log("Location.js - create() ") const startTime = performance.now(); const newUrl = await this.sync('create', this, { url: this.create.url(this.id) }, { silent: true }); const duration = performance.now() - startTime; console.log(`PERFORMANACE CHECK: Location.js - the function create() took ${duration}ms`); return newUrl; },Esto permitirá que su función muestre los registros de rendimiento antes de devolver el valor creado.