Skip to content

Latest commit

 

History

History
40 lines (37 loc) · 1.51 KB

global.loadWithGlobalPool.md

File metadata and controls

40 lines (37 loc) · 1.51 KB

loadWithGlobalPool

The loadWithGlobalPool function is established to load and evaluate script from a script object with a pool to store the script context.

Sample

var runscript=`
	var pdfDataUri;
	for(var i=0;i<10;i++){
		var pdfDoc=await(PDFLib.PDFDocument.create());
		var page = pdfDoc.addPage([350, 400]);
		page.moveTo(110, 200);
		page.drawText(msg);
		pdfDataUri=await(pdfDoc.saveAsBase64({ dataUri: true }));
	}
	pdfDataUri;
`;
var pdfDataUri=loadWithGlobalPool({
	name:"pdf-lib",
	max:3,
	initializer:"load(_eventfolder+'/pdf-lib.min.js');",
	script:runscript,
	context:{msg:"Hello World!"},
	engine:"nashorn",
	returnVar:"pdfDataUri"
});
return new Result().eval("$('"+params.pdf+"')[0].src='" +pdfDataUri +"'");

API

ParametersTypeDescription
nameStringThe name of the pool.
maxNumberThe max size of the pool.
initializerStringScript string executed by the pool when initializing the script context.
scriptStringScript string executed by the pool on call.
contextObjectThe attributes of the context parameter will be set into the global of the script context.
engineStringThe name of the engines in the pool.Only "nashorn" or "javet".
returnVarStringThe var name to get the return value.