How to use ensureNotTerminated method in wpt

Best JavaScript code snippet using wpt

worker.js

Source:worker.js Github

copy

Full Screen

...49 },50 terminate() {51 this.terminated = true;52 },53 ensureNotTerminated() {54 if (this.terminated) {55 throw new Error("Worker task was terminated");56 }57 },58 };59 return WorkerTask;60})();61var WorkerMessageHandler = {62 setup(handler, port) {63 var testMessageProcessed = false;64 handler.on("test", function wphSetupTest(data) {65 if (testMessageProcessed) {66 return; // we already processed 'test' message once67 }68 testMessageProcessed = true;69 // check if Uint8Array can be sent to worker70 if (!(data instanceof Uint8Array)) {71 handler.send("test", null);72 return;73 }74 // making sure postMessage transfers are working75 const supportTransfers = data[0] === 255;76 handler.postMessageTransfers = supportTransfers;77 handler.send("test", { supportTransfers });78 });79 handler.on("configure", function wphConfigure(data) {80 setVerbosityLevel(data.verbosity);81 });82 handler.on("GetDocRequest", function wphSetupDoc(data) {83 return WorkerMessageHandler.createDocumentHandler(data, port);84 });85 },86 createDocumentHandler(docParams, port) {87 // This context is actually holds references on pdfManager and handler,88 // until the latter is destroyed.89 var pdfManager;90 var terminated = false;91 var cancelXHRs = null;92 var WorkerTasks = [];93 const verbosity = getVerbosityLevel();94 const apiVersion = docParams.apiVersion;95 const workerVersion =96 typeof PDFJSDev !== "undefined" && !PDFJSDev.test("TESTING")97 ? PDFJSDev.eval("BUNDLE_VERSION")98 : null;99 if (apiVersion !== workerVersion) {100 throw new Error(101 `The API version "${apiVersion}" does not match ` +102 `the Worker version "${workerVersion}".`103 );104 }105 var docId = docParams.docId;106 var docBaseUrl = docParams.docBaseUrl;107 var workerHandlerName = docParams.docId + "_worker";108 var handler = new MessageHandler(workerHandlerName, docId, port);109 // Ensure that postMessage transfers are always correctly enabled/disabled,110 // to prevent "DataCloneError" in browsers without transfers support.111 handler.postMessageTransfers = docParams.postMessageTransfers;112 function ensureNotTerminated() {113 if (terminated) {114 throw new Error("Worker was terminated");115 }116 }117 function startWorkerTask(task) {118 WorkerTasks.push(task);119 }120 function finishWorkerTask(task) {121 task.finish();122 var i = WorkerTasks.indexOf(task);123 WorkerTasks.splice(i, 1);124 }125 async function loadDocument(recoveryMode) {126 await pdfManager.ensureDoc("checkHeader");127 await pdfManager.ensureDoc("parseStartXRef");128 await pdfManager.ensureDoc("parse", [recoveryMode]);129 if (!recoveryMode) {130 // Check that at least the first page can be successfully loaded,131 // since otherwise the XRef table is definitely not valid.132 await pdfManager.ensureDoc("checkFirstPage");133 }134 const [numPages, fingerprint] = await Promise.all([135 pdfManager.ensureDoc("numPages"),136 pdfManager.ensureDoc("fingerprint"),137 ]);138 return { numPages, fingerprint };139 }140 function getPdfManager(data, evaluatorOptions) {141 var pdfManagerCapability = createPromiseCapability();142 var pdfManager;143 var source = data.source;144 if (source.data) {145 try {146 pdfManager = new LocalPdfManager(147 docId,148 source.data,149 source.password,150 evaluatorOptions,151 docBaseUrl152 );153 pdfManagerCapability.resolve(pdfManager);154 } catch (ex) {155 pdfManagerCapability.reject(ex);156 }157 return pdfManagerCapability.promise;158 }159 var pdfStream,160 cachedChunks = [];161 try {162 pdfStream = new PDFWorkerStream(handler);163 } catch (ex) {164 pdfManagerCapability.reject(ex);165 return pdfManagerCapability.promise;166 }167 var fullRequest = pdfStream.getFullReader();168 fullRequest.headersReady169 .then(function() {170 if (!fullRequest.isRangeSupported) {171 return;172 }173 // We don't need auto-fetch when streaming is enabled.174 var disableAutoFetch =175 source.disableAutoFetch || fullRequest.isStreamingSupported;176 pdfManager = new NetworkPdfManager(177 docId,178 pdfStream,179 {180 msgHandler: handler,181 password: source.password,182 length: fullRequest.contentLength,183 disableAutoFetch,184 rangeChunkSize: source.rangeChunkSize,185 },186 evaluatorOptions,187 docBaseUrl188 );189 // There may be a chance that `pdfManager` is not initialized190 // for first few runs of `readchunk` block of code. Be sure191 // to send all cached chunks, if any, to chunked_stream via192 // pdf_manager.193 for (let i = 0; i < cachedChunks.length; i++) {194 pdfManager.sendProgressiveData(cachedChunks[i]);195 }196 cachedChunks = [];197 pdfManagerCapability.resolve(pdfManager);198 cancelXHRs = null;199 })200 .catch(function(reason) {201 pdfManagerCapability.reject(reason);202 cancelXHRs = null;203 });204 var loaded = 0;205 var flushChunks = function() {206 var pdfFile = arraysToBytes(cachedChunks);207 if (source.length && pdfFile.length !== source.length) {208 warn("reported HTTP length is different from actual");209 }210 // the data is array, instantiating directly from it211 try {212 pdfManager = new LocalPdfManager(213 docId,214 pdfFile,215 source.password,216 evaluatorOptions,217 docBaseUrl218 );219 pdfManagerCapability.resolve(pdfManager);220 } catch (ex) {221 pdfManagerCapability.reject(ex);222 }223 cachedChunks = [];224 };225 var readPromise = new Promise(function(resolve, reject) {226 var readChunk = function(chunk) {227 try {228 ensureNotTerminated();229 if (chunk.done) {230 if (!pdfManager) {231 flushChunks();232 }233 cancelXHRs = null;234 return;235 }236 var data = chunk.value;237 loaded += arrayByteLength(data);238 if (!fullRequest.isStreamingSupported) {239 handler.send("DocProgress", {240 loaded,241 total: Math.max(loaded, fullRequest.contentLength || 0),242 });243 }244 if (pdfManager) {245 pdfManager.sendProgressiveData(data);246 } else {247 cachedChunks.push(data);248 }249 fullRequest.read().then(readChunk, reject);250 } catch (e) {251 reject(e);252 }253 };254 fullRequest.read().then(readChunk, reject);255 });256 readPromise.catch(function(e) {257 pdfManagerCapability.reject(e);258 cancelXHRs = null;259 });260 cancelXHRs = function(reason) {261 pdfStream.cancelAllRequests(reason);262 };263 return pdfManagerCapability.promise;264 }265 function setupDoc(data) {266 function onSuccess(doc) {267 ensureNotTerminated();268 handler.send("GetDoc", { pdfInfo: doc });269 }270 function onFailure(ex) {271 ensureNotTerminated();272 if (ex instanceof PasswordException) {273 var task = new WorkerTask(`PasswordException: response ${ex.code}`);274 startWorkerTask(task);275 handler276 .sendWithPromise("PasswordRequest", ex)277 .then(function(data) {278 finishWorkerTask(task);279 pdfManager.updatePassword(data.password);280 pdfManagerReady();281 })282 .catch(function() {283 finishWorkerTask(task);284 handler.send("DocException", ex);285 });286 } else if (287 ex instanceof InvalidPDFException ||288 ex instanceof MissingPDFException ||289 ex instanceof UnexpectedResponseException ||290 ex instanceof UnknownErrorException291 ) {292 handler.send("DocException", ex);293 } else {294 handler.send(295 "DocException",296 new UnknownErrorException(ex.message, ex.toString())297 );298 }299 }300 function pdfManagerReady() {301 ensureNotTerminated();302 loadDocument(false).then(303 onSuccess,304 function loadFailure(ex) {305 ensureNotTerminated();306 // Try again with recoveryMode == true307 if (!(ex instanceof XRefParseException)) {308 onFailure(ex);309 return;310 }311 pdfManager.requestLoadedStream();312 pdfManager.onLoadedStream().then(function() {313 ensureNotTerminated();314 loadDocument(true).then(onSuccess, onFailure);315 });316 },317 onFailure318 );319 }320 ensureNotTerminated();321 var evaluatorOptions = {322 forceDataSchema: data.disableCreateObjectURL,323 maxImageSize: data.maxImageSize,324 disableFontFace: data.disableFontFace,325 nativeImageDecoderSupport: data.nativeImageDecoderSupport,326 ignoreErrors: data.ignoreErrors,327 isEvalSupported: data.isEvalSupported,328 };329 getPdfManager(data, evaluatorOptions)330 .then(function(newPdfManager) {331 if (terminated) {332 // We were in a process of setting up the manager, but it got333 // terminated in the middle.334 newPdfManager.terminate(...

Full Screen

Full Screen

transaction.ts

Source:transaction.ts Github

copy

Full Screen

...7 private readonly accessExclusiveLockTables: Array<string>,8 private readonly advisoryLockKeys: Array<number>) {9 }10 public query(query: string, values?: Array<any>): Promise<pg.QueryResult> {11 this.ensureNotTerminated()12 return this.client.query(query, values)13 }14 public ensureHasAccessExclusiveLock(table: string) {15 this.ensureNotTerminated()16 if (!this.accessExclusiveLockTables.includes(table)) {17 throw new Error(`Access Exclusive lock on table '${table}' is required but missing`)18 }19 this.ensuredAccessExclusiveLockTables.add(table)20 }21 public ensureHasAdvisoryLock(key: number) {22 this.ensureNotTerminated()23 if (!this.advisoryLockKeys.includes(key)) {24 throw new Error(`Advisory lock on key ${key} is required but missing`)25 }26 this.ensuredAdvisoryLockKeys.add(key)27 }28 public terminate() {29 this.ensureNotTerminated()30 this.terminated = true31 for (const table of this.accessExclusiveLockTables) {32 if (!this.ensuredAccessExclusiveLockTables.has(table)) {33 throw new Error(`Unnecessary lock declaration for table '${table}'`)34 }35 }36 for (const key of this.advisoryLockKeys) {37 if (!this.ensuredAdvisoryLockKeys.has(key)) {38 throw new Error(`Unnecessary lock declaration for key ${key}`)39 }40 }41 }42 private ensureNotTerminated(): void {43 if (this.terminated) {44 throw new Error('Transaction terminated')45 }46 }...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest');2var wpt = new WebPageTest('www.webpagetest.org');3wpt.ensureNotTerminated('1234', function(err, data) {4 if (err) {5 console.log('error', err);6 } else {7 console.log('data', data);8 }9});10{ statusCode: 200,11 data: { statusCode: 200, statusText: 'Ok' } }12{ statusCode: 200,13 data: { statusCode: 200, statusText: 'Ok' } }14{ statusCode: 200,15 data: { statusCode: 200, statusText: 'Ok' } }16{ statusCode: 200,17 data: { statusCode: 200, statusText: 'Ok' } }18{ statusCode: 200,19 data: { statusCode: 200, statusText: 'Ok' } }20{ statusCode: 200,21 data: { statusCode: 200, statusText: 'Ok' } }22{ statusCode: 200,23 data: { statusCode: 200, statusText: 'Ok' } }24{ statusCode: 200,25 data: { statusCode: 200, statusText: 'Ok' } }26{ statusCode: 200,27 data: { statusCode: 200, statusText: 'Ok' } }28{ statusCode: 200,29 data: { statusCode: 200, statusText: 'Ok' } }30{ statusCode: 200,31 data: { statusCode: 200, statusText: 'Ok'

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('wpt');2wpt.ensureNotTerminated('1234', function (err, result) {3 if (err) {4 console.log(err);5 }6 else {7 console.log(result);8 }9});10var wpt = require('wpt');11wpt.getLocations(function (err, result) {12 if (err) {13 console.log(err);14 }15 else {16 console.log(result);17 }18});19var wpt = require('wpt');20wpt.getTesters(function (err, result) {21 if (err) {22 console.log(err);23 }24 else {25 console.log(result);26 }27});28var wpt = require('wpt');29wpt.getTesters(function (err, result) {30 if (err) {31 console.log(err);32 }33 else {34 console.log(result);35 }36});37var wpt = require('wpt');38wpt.getTesters(function (err, result) {39 if (err) {40 console.log(err);41 }42 else {43 console.log(result);44 }45});46var wpt = require('wpt');47wpt.getTesters(function (err, result) {48 if (err) {49 console.log(err);50 }51 else {52 console.log(result);53 }54});55var wpt = require('wpt');56wpt.getTesters(function (err, result) {57 if (err) {58 console.log(err);59 }60 else {61 console.log(result);62 }63});64var wpt = require('wpt');65wpt.getTesters(function (err, result) {66 if (err) {67 console.log(err);68 }69 else {70 console.log(result);71 }72});

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptoolkit = require('wptoolkit');2wptoolkit.ensureNotTerminated();3var page = require('webpage').create();4 console.log("Status: " + status);5 if(status === "success") {6 page.render('google.png');7 }8 phantom.exit();9});10 wptoolkit.ensureNotTerminated();

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('wpt.js');2var wpt = new WebPageTest('www.webpagetest.org');3wpt.getLocations(function (err, data) {4 if (err) {5 } else {6 }7});8 if (err) {9 } else {10 }11});12wpt.ensureNotTerminated('testId', function (err, data) {13 if (err) {14 } else {15 }16});17wpt.getTestResults('testId', function (err, data) {18 if (err) {19 } else {20 }21});22wpt.getTestResults('testId', function (err, data) {23 if (err) {24 } else {25 }26});27wpt.getTestResults('testId', function (err, data) {28 if (err) {29 } else {30 }31});32wpt.getTestResults('testId', function (err, data) {33 if (err) {34 } else {35 }36});

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('wpt');2var ensureNotTerminated = wpt.ensureNotTerminated;3var wpt = new Wpt();4ensureNotTerminated(wpt, function(err, data) {5 if (err) {6 console.log(err);7 } else {8 console.log(data);9 }10});11var wpt = require('wpt');12var ensureTerminated = wpt.ensureTerminated;13var wpt = new Wpt();14ensureTerminated(wpt, function(err, data) {15 if (err) {16 console.log(err);17 } else {18 console.log(data);19 }20});21var wpt = require('wpt');22var getLocations = wpt.getLocations;23var wpt = new Wpt();24getLocations(wpt, function(err, data) {25 if (err) {26 console.log(err);27 } else {28 console.log(data);29 }30});31var wpt = require('wpt');32var getTests = wpt.getTests;33var wpt = new Wpt();34getTests(wpt, function(err, data) {35 if (err) {36 console.log(err);37 } else {38 console.log(data);39 }40});41var wpt = require('wpt');42var setTest = wpt.setTest;43var wpt = new Wpt();44setTest(wpt, function(err, data) {45 if (err) {46 console.log(err);47 } else {48 console.log(data);49 }50});51var wpt = require('wpt');52var setTest = wpt.setTest;53var wpt = new Wpt();54setTest(wpt, function(err, data) {55 if (err)

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run wpt automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful