@@ -296,31 +296,32 @@ Worker.prototype.save = function save(filename) {
296296/* ----- SET / GET ----- */
297297
298298Worker . prototype . set = function set ( opt ) {
299- // Set properties within the promise chain.
300299 // TODO: Test null/undefined input to this function.
301300 // TODO: Implement ordered pairs?
302- return this . then ( async function set_main ( ) {
303- for ( var key in opt ) {
301+
302+ // Build an array of setter functions to queue.
303+ var fns = Object . keys ( opt || { } ) . map ( function ( key ) {
304304 if ( key in Worker . template . prop ) {
305305 // Set pre-defined properties.
306- this . prop [ key ] = opt [ key ] ;
306+ return function set_prop ( ) { this . prop [ key ] = opt [ key ] ; }
307307 } else {
308308 switch ( key ) {
309309 case 'margin' :
310- await this . setMargin ( opt . margin ) ;
311- break ;
310+ return this . setMargin . bind ( this , opt . margin ) ;
312311 case 'jsPDF' :
313- // Include jsPDF here because it must also update pageSize.
314- this . opt . jsPDF = opt . jsPDF ;
312+ return function set_jsPDF ( ) { this . opt . jsPDF = opt . jsPDF ; return this . setPageSize ( ) ; }
315313 case 'pageSize' :
316- await this . setPageSize ( opt . pageSize ) ;
317- break ;
314+ return this . setPageSize . bind ( this , opt . pageSize ) ;
318315 default :
319316 // Set any other properties in opt.
320- this . opt [ key ] = opt [ key ] ;
317+ return function set_opt ( ) { this . opt [ key ] = opt [ key ] } ;
321318 }
322319 }
323- }
320+ } , this ) ;
321+
322+ // Set properties within the promise chain.
323+ return this . then ( function set_main ( ) {
324+ return this . thenList ( fns ) ;
324325 } ) ;
325326} ;
326327
0 commit comments