polotno-node 2.6.6 → 2.6.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/instance.js +14 -0
  2. package/package.json +1 -1
package/instance.js CHANGED
@@ -73,6 +73,8 @@ module.exports.jsonToBlob = async (page, json, attrs) => {
73
73
  );
74
74
  };
75
75
 
76
+ const busyPages = [];
77
+
76
78
  module.exports.createInstance = async ({
77
79
  key,
78
80
  url,
@@ -89,6 +91,14 @@ module.exports.createInstance = async ({
89
91
  ? await module.exports.createPage(browser, visitPage)
90
92
  : firstPage;
91
93
 
94
+ if (busyPages.indexOf(page) >= 0) {
95
+ throw new Error(
96
+ 'Current rendering context is busy with another task. Please use `useParallelPages: true` option to run multiple tasks in parallel or make sure previous task is finished before starting a new one.'
97
+ );
98
+ }
99
+
100
+ busyPages.push(page);
101
+
92
102
  try {
93
103
  if (args[1]?.assetLoadTimeout) {
94
104
  await page.evaluate((timeout) => {
@@ -135,11 +145,15 @@ module.exports.createInstance = async ({
135
145
  throw new Error(error);
136
146
  }
137
147
  }
148
+ // remove busy page
149
+ busyPages.splice(busyPages.indexOf(page), 1);
138
150
  if (useParallelPages) {
139
151
  await page.close();
140
152
  }
141
153
  return result;
142
154
  } catch (e) {
155
+ // remove busy page
156
+ busyPages.splice(busyPages.indexOf(page), 1);
143
157
  if (useParallelPages) {
144
158
  await page.close();
145
159
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "polotno-node",
3
- "version": "2.6.6",
3
+ "version": "2.6.7",
4
4
  "description": "Polotno workflow from NodeJS",
5
5
  "main": "index.js",
6
6
  "scripts": {