dsh-mo-image 0.7.0 → 1.0.0

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.
@@ -5,13 +5,13 @@
5
5
  * index.js 只负责装配与工具入口;这里只依赖适配器层的纯函数和 Worker 客户端,
6
6
  * 不读配置、不发请求,测试也就能直接针对成图行为。
7
7
  */
8
- import { mkdirSync } from 'node:fs';
9
- import { writeFile } from 'node:fs/promises';
8
+ import { mkdir, open, rename, unlink, writeFile } from 'node:fs/promises';
10
9
  import path from 'node:path';
11
10
  import { randomUUID } from 'node:crypto';
12
11
 
13
12
  import { aspectLabel, comfySizeWritable, imageSizeOf, resizeTo } from './adapters.js';
14
13
  import { resizeInWorker } from './image-worker.js';
14
+ import { isPng } from './png-scale.js';
15
15
 
16
16
  /** 从 content-type 猜扩展名;只有成品文件名用它,认不出按 png。 */
17
17
  export function safeExt(contentType) {
@@ -58,147 +58,91 @@ export function applySizeStitch(prompt, fitted, adapter, provider, model) {
58
58
  };
59
59
  }
60
60
 
61
- /**
62
- * 收尾:读出回图真实尺寸,按严格模式决定要不要缩放,并把原始尺寸一并回报。
63
- *
64
- * 目标值只来自「请求里实际带的那个尺寸」(`fitted.requested`):
65
- * 固定尺寸下是选择器的值,自动尺寸下是对话模型填进 size 的值。
66
- * 档位名(`2K`)没有像素含义,官方连 2048×2048 都不保证,所以不拿它当目标。
67
- */
68
- export function finalizeImage(result, options, log = () => {}) {
69
- const strict = Boolean(options && options.strict === true);
70
- let bytes = result.bytes;
71
- let contentType = result.contentType;
72
- let fitted = result.fitted;
73
- let note = result && result.note ? String(result.note) : '';
74
- const actual = imageSizeOf(bytes);
75
- const generated = actual && actual.width && actual.height ? actual.width + 'x' + actual.height : '';
76
- const omit = !fitted || fitted.omit || fitted.size === 'none';
77
- const wanted = fitted && fitted.requested ? fitted.requested : null;
78
- const wantedPixels = wanted ? wanted.width * wanted.height : 0;
79
- const fittedPixels = fitted ? (fitted.width || 0) * (fitted.height || 0) : 0;
80
- const appendNote = (text) => { note = note ? note + ';' + text : text; };
61
+ const WORKER_MIN_PIXELS = 512 * 1024;
81
62
 
82
- if (strict) {
83
- if (!wanted || !wanted.width || !wanted.height) {
84
- appendNote(omit
85
- ? '自动尺寸且请求未带尺寸,严格模式未生效'
86
- : '该模型按档位出图,没有固定像素目标,严格模式未生效');
87
- } else if (actual && (actual.width !== wanted.width || actual.height !== wanted.height)) {
88
- const upscale = actual.width * actual.height < wanted.width * wanted.height;
89
- // 缩之前留一份:严格模式改了像素,上游原图反而是没法再拿到的。
90
- const originalBytes = bytes;
91
- const resized = resizeTo(bytes, wanted.width, wanted.height, 'cover');
92
- if (resized) {
93
- bytes = resized.bytes;
94
- contentType = resized.contentType;
95
- fitted = Object.assign({}, fitted, {
96
- size: wanted.text || (wanted.width + 'x' + wanted.height),
97
- width: wanted.width,
98
- height: wanted.height,
99
- adjusted: false
100
- });
101
- appendNote('严格模式:上游出图 ' + generated + ',已' + (resized.cropped ? '裁切并' : '')
102
- + '缩放到 ' + fitted.size + (upscale ? '(已放大,画质有损)' : ''));
103
- return {
104
- bytes: bytes, contentType: contentType, fitted: fitted, note: note,
105
- generated: generated, original: originalBytes
106
- };
107
- }
108
- appendNote('严格模式:上游出图 ' + generated + ',未能缩放到 '
109
- + (wanted.text || wanted.width + 'x' + wanted.height) + ',成图保持原尺寸');
110
- }
111
- return { bytes: bytes, contentType: contentType, fitted: fitted, note: note, generated: generated };
112
- }
63
+ /** 只用请求里明确给出的宽高做缩放目标,档位名没有固定像素尺寸。 */
64
+ function resizePlan(result, options) {
65
+ const strict = options?.strict === true;
66
+ const fitted = result.fitted;
67
+ const requested = fitted?.requested;
68
+ const wanted = requested?.width && requested?.height ? requested : null;
69
+ const actual = imageSizeOf(result.bytes);
70
+ const sourcePixels = actual ? actual.width * actual.height : 0;
71
+ const targetPixels = wanted ? wanted.width * wanted.height : 0;
72
+ const fittedPixels = (fitted?.width || 0) * (fitted?.height || 0);
73
+ const matches = Boolean(actual && wanted && actual.width === wanted.width && actual.height === wanted.height);
74
+ // 非严格模式只有在尺寸适配时抬大过请求,才尝试缩回去。
75
+ const downscale = fitted?.adjusted && wanted && wanted.text !== fitted.size && fittedPixels > targetPixels;
76
+ const resize = Boolean(wanted && !matches && (strict ? actual : downscale));
77
+ return { strict, wanted, actual, sourcePixels, targetPixels, fittedPixels, matches, resize };
78
+ }
113
79
 
114
- // 非严格模式:只有我们自己把尺寸落大过,才缩回用户要的尺寸。
115
- if (fitted && fitted.adjusted && wanted && wanted.width && wanted.height
116
- && wanted.text !== fitted.size && fittedPixels > wantedPixels) {
117
- const resized = resizeTo(bytes, wanted.width, wanted.height);
118
- if (resized) {
119
- bytes = resized.bytes;
120
- contentType = resized.contentType;
121
- log('resize ' + fitted.size + ' → ' + wanted.text);
122
- fitted = Object.assign({}, fitted, { size: wanted.text, width: wanted.width, height: wanted.height, adjusted: false });
80
+ function withSize(fitted, dimensions, adjusted) {
81
+ const { width, height } = dimensions;
82
+ return { ...fitted, size: width + 'x' + height, width, height, omit: false, adjusted };
83
+ }
84
+
85
+ function finalizeResult(result, plan, resized, log) {
86
+ const { strict, wanted, actual, sourcePixels, targetPixels, fittedPixels, matches, resize } = plan;
87
+ const { bytes, contentType, fitted } = result;
88
+ const generated = actual ? actual.width + 'x' + actual.height : '';
89
+ const output = { bytes, contentType, fitted, note: String(result.note || ''), generated };
90
+ const appendNote = (text) => { output.note = output.note ? output.note + ';' + text : text; };
91
+ if (strict && !wanted) {
92
+ const omit = !fitted || fitted.omit || fitted.size === 'none';
93
+ appendNote(omit
94
+ ? '自动尺寸且请求未带尺寸,严格模式未生效'
95
+ : '该模型按档位出图,没有固定像素目标,严格模式未生效');
96
+ return output;
97
+ }
98
+ const target = wanted ? wanted.width + 'x' + wanted.height : '';
99
+ if (resize && resized) {
100
+ output.bytes = resized.bytes;
101
+ output.contentType = resized.contentType;
102
+ output.fitted = withSize(fitted, wanted, false);
103
+ if (strict) {
104
+ output.original = bytes;
105
+ appendNote('严格模式:上游出图 ' + generated + ',已' + (resized.cropped ? '裁切并' : '')
106
+ + '缩放到 ' + target + (sourcePixels < targetPixels ? '(已放大,画质有损)' : ''));
123
107
  } else {
124
- log('resize unavailable, keep ' + fitted.size + '(用户要 ' + wanted.text + ')');
108
+ log('resize ' + (generated || fitted.size) + ' → ' + target);
125
109
  }
126
- } else if (fitted && fitted.adjusted && wanted && fittedPixels < wantedPixels) {
127
- const sizeNote = '该模型上限为 ' + fitted.size + ',已按上限生成(请求 ' + wanted.text + ',未放大)。';
128
- appendNote(sizeNote);
129
- log('keep model max ' + fitted.size + '(用户要 ' + wanted.text + ',不放大)');
110
+ } else if (resize || (strict && !actual)) {
111
+ if (actual) output.fitted = withSize(fitted, actual, true);
112
+ const upstream = generated ? '上游出图 ' + generated : '无法读取上游出图尺寸';
113
+ appendNote((strict ? '严格模式:' : '') + upstream + ',未能缩放到 ' + target + ',已保留原图');
114
+ log('resize unavailable, keep original ' + generated + '(用户要 ' + target + ')');
115
+ } else if (matches) {
116
+ output.fitted = withSize(fitted, wanted, false);
117
+ } else if (!strict && fitted?.adjusted && wanted && fittedPixels < targetPixels) {
118
+ appendNote('该模型上限为 ' + fitted.size + ',已按上限生成(请求 ' + target + ',未放大)。');
119
+ log('keep model max ' + fitted.size + '(用户要 ' + target + ',不放大)');
130
120
  }
131
- return { bytes: bytes, contentType: contentType, fitted: fitted, note: note, generated: generated };
121
+ return output;
132
122
  }
133
123
 
134
- /**
135
- * 只有大图、且确实需要缩放时才进 Worker;小图/非 PNG 继续走同步的
136
- * `finalizeImage`,省掉 Worker 的启动与消息开销。
137
- */
138
- const WORKER_MIN_PIXELS = 512 * 1024;
139
-
140
- function workerResizePlan(result, options) {
141
- const strict = Boolean(options && options.strict === true);
142
- const fitted = result && result.fitted;
143
- const wanted = fitted && fitted.requested ? fitted.requested : null;
144
- if (!wanted || !wanted.width || !wanted.height) return null;
145
- const actual = imageSizeOf(result && result.bytes);
146
- if (!actual || !actual.width || !actual.height) return null;
147
- const same = actual.width === wanted.width && actual.height === wanted.height;
148
- if (strict) return same ? null : { strict: true, mode: 'cover', actual: actual, wanted: wanted };
149
- const fittedPixels = (fitted.width || 0) * (fitted.height || 0);
150
- const wantedPixels = wanted.width * wanted.height;
151
- if (fitted.adjusted && wanted.text !== fitted.size && fittedPixels > wantedPixels) {
152
- return { strict: false, mode: undefined, actual: actual, wanted: wanted };
153
- }
154
- return null;
124
+ export function finalizeImage(result, options, log = () => {}) {
125
+ const plan = resizePlan(result, options);
126
+ const resized = plan.resize
127
+ ? resizeTo(result.bytes, plan.wanted.width, plan.wanted.height, plan.strict ? 'cover' : undefined)
128
+ : null;
129
+ return finalizeResult(result, plan, resized, log);
155
130
  }
156
131
 
157
- /**
158
- * 异步版收尾:把大图的解码/裁切/缩放/编码放到 Worker;Worker 不可用、
159
- * 超时或遇到非 PNG 时自动退回同步 `finalizeImage`,行为与原来完全一致。
160
- */
132
+ /** 大 PNG 只交给 Worker,失败时保留原图。小图和其他格式沿用原有缩放路径。 */
161
133
  export async function finalizeImageAsync(result, options, log = () => {}) {
162
- const plan = workerResizePlan(result, options);
163
- if (!plan) return finalizeImage(result, options, log);
164
- const sourcePixels = plan.actual.width * plan.actual.height;
165
- const targetPixels = plan.wanted.width * plan.wanted.height;
166
- if (Math.max(sourcePixels, targetPixels) < WORKER_MIN_PIXELS) return finalizeImage(result, options, log);
167
-
134
+ const plan = resizePlan(result, options);
168
135
  let resized = null;
169
- try {
170
- resized = await resizeInWorker(result.bytes, plan.wanted.width, plan.wanted.height, plan.mode);
171
- } catch (_error) {
172
- resized = null;
173
- }
174
- if (!resized) return finalizeImage(result, options, log);
175
-
176
- // 已经缩好了,再让 finalizeImage 只负责 generate/note 等元数据;不能让它在
177
- // 主线程把同一张图再解一遍。
178
- const merged = Object.assign({}, result, {
179
- bytes: resized.bytes,
180
- contentType: resized.contentType,
181
- fitted: Object.assign({}, result.fitted, { adjusted: false })
182
- });
183
- const final = finalizeImage(merged, options, log);
184
- const wanted = plan.wanted;
185
- const fitted = Object.assign({}, final.fitted, {
186
- size: wanted.text || (wanted.width + 'x' + wanted.height),
187
- width: wanted.width, height: wanted.height, adjusted: false
188
- });
189
- const generated = plan.actual.width + 'x' + plan.actual.height;
190
- let note = final.note || '';
191
- const append = (text) => { note = note ? note + ';' + text : text; };
192
- if (plan.strict) {
193
- const upscale = sourcePixels < targetPixels;
194
- append('严格模式:上游出图 ' + generated + ',已' + (resized.cropped ? '裁切并' : '')
195
- + '缩放到 ' + fitted.size + (upscale ? '(已放大,画质有损)' : ''));
136
+ if (plan.resize) {
137
+ const { width, height } = plan.wanted;
138
+ const mode = plan.strict ? 'cover' : undefined;
139
+ if (isPng(result.bytes) && Math.max(plan.sourcePixels, plan.targetPixels) >= WORKER_MIN_PIXELS) {
140
+ resized = await resizeInWorker(result.bytes, width, height, mode);
141
+ } else {
142
+ resized = resizeTo(result.bytes, width, height, mode);
143
+ }
196
144
  }
197
- return Object.assign({}, final, {
198
- bytes: resized.bytes, contentType: resized.contentType, fitted: fitted,
199
- note: note, generated: generated,
200
- original: plan.strict ? result.bytes : final.original
201
- });
145
+ return finalizeResult(result, plan, resized, log);
202
146
  }
203
147
 
204
148
  /** 生成图旁边留一份上游原图(严格模式缩过图时用)。 */
@@ -217,10 +161,29 @@ export async function saveSidecar(bytes, contentType, file, log = () => {}) {
217
161
 
218
162
  /** 把成品写进调用方选定的目录(当前项目 generated-images 或 DSH 状态目录)。 */
219
163
  export async function saveImage(bytes, contentType, provider, model, size, dir) {
220
- mkdirSync(dir, { recursive: true });
164
+ await mkdir(dir, { recursive: true });
221
165
  const ext = safeExt(contentType);
222
166
  const filename = 'mo-' + Date.now() + '-' + randomUUID().slice(0, 8) + '.' + ext;
223
167
  const file = path.join(dir, filename);
224
- await writeFile(file, bytes);
168
+ const tmp = file + '.tmp';
169
+ try {
170
+ await writeFile(tmp, bytes, { flag: 'wx' });
171
+ await rename(tmp, file);
172
+ } catch (error) {
173
+ if (error.code !== 'EEXIST') await unlink(tmp).catch(() => {});
174
+ throw error;
175
+ }
225
176
  return { file, filename, provider: provider.name || provider.id, model, size, bytes: bytes.length, contentType };
226
177
  }
178
+
179
+ /** 提交付费请求前确认能在目标目录创建文件,兼容 Windows 的目录 ACL。 */
180
+ export async function checkImageOutput(dir) {
181
+ await mkdir(dir, { recursive: true });
182
+ const probe = path.join(dir, '.mo-write-' + randomUUID() + '.tmp');
183
+ const file = await open(probe, 'wx', 0o600);
184
+ try {
185
+ await file.close();
186
+ } finally {
187
+ await unlink(probe);
188
+ }
189
+ }
@@ -2,17 +2,15 @@
2
2
  * 大图处理的受控 Worker(OPTIMIZATION_PLAN 阶段 D2)。
3
3
  *
4
4
  * 主线程只负责收图和落盘;解码、裁切、缩放、编码都在 Worker 里做。
5
- * 一个 4K PNG 解码后是 33MB 的 RGBA,在主线程上做面积平均缩放会把事件循环
6
- * 顶住几百毫秒,设置页和对话流都会卡;Worker 里做,主线程只等一条消息。
5
+ * 主线程串行提交,只有正在处理的图片需要复制并转移到 Worker。
7
6
  *
8
- * 失败一律回 null,让调用方退回同步的 `resizeTo()`;Worker 起不来、超时、
9
- * 图片格式不支持都不应该让一次生图失败。并发 1 个 Worker 是有意的:
10
- * 上游本身已经有 2 并发的队列,这里再开多线程只会抢 CPU 和内存。
7
+ * 失败返回 null,调用方可以保留上游原图。运行中的任务超时后停止整个 Worker,
8
+ * 等它退出后再处理队列,避免同时有两份像素缓冲区和缩放任务。
11
9
  */
12
10
  import { isMainThread, parentPort, Worker } from 'node:worker_threads';
13
11
  import { Buffer } from 'node:buffer';
14
12
 
15
- import { decodePng, encodePng, resizeRgba } from './png-scale.js';
13
+ import { decodePng, encodePng, pngHeaderOf, resizeRgba } from './png-scale.js';
16
14
 
17
15
  const MAX_SIDE = 16384;
18
16
  const MAX_PIXELS = 32 * 1024 * 1024;
@@ -94,49 +92,77 @@ if (!isMainThread && parentPort) {
94
92
  /* ----------------------------------------------------------------- 主线程 */
95
93
 
96
94
  let worker = null;
95
+ let stopping = false;
96
+ let running = null;
97
97
  let nextId = 1;
98
- const pending = new Map();
98
+ const queue = new Map();
99
99
 
100
- function settleAll() {
101
- for (const entry of pending.values()) {
102
- clearTimeout(entry.timer);
103
- entry.resolve(null);
104
- }
105
- pending.clear();
106
- worker = null;
100
+ function settle(job, result) {
101
+ clearTimeout(job.timer);
102
+ job.resolve(result);
103
+ }
104
+
105
+ function clearQueue() {
106
+ for (const job of queue.values()) settle(job, null);
107
+ queue.clear();
108
+ }
109
+
110
+ function stopWorker() {
111
+ if (!worker || stopping) return;
112
+ stopping = true;
113
+ // exit() 恢复调度。新 Worker 必须等旧 Worker 释放计算和缓冲区后再启动。
114
+ void worker.terminate().catch(() => {});
107
115
  }
108
116
 
109
- function ensureWorker() {
110
- if (worker) return worker;
117
+ function completeRunning(result) {
118
+ const job = running;
119
+ running = null;
120
+ if (job) settle(job, result);
121
+ }
122
+
123
+ function createWorker() {
111
124
  const created = new Worker(new URL('./image-worker.js', import.meta.url));
112
- worker = created;
113
- // 不因为这个 Worker 让宿主进程无法退出;每次请求仍有自己的超时。
114
- if (typeof created.unref === 'function') created.unref();
115
125
  created.on('message', (message) => {
116
- const entry = pending.get(message && message.id);
117
- if (!entry) return;
118
- pending.delete(entry.id);
119
- clearTimeout(entry.timer);
120
- if (message.ok && message.bytes) {
121
- entry.resolve({
122
- bytes: Buffer.from(message.bytes),
123
- contentType: 'image/png',
124
- resized: true,
125
- cropped: !!message.cropped
126
- });
127
- } else {
128
- entry.resolve(null);
129
- }
130
- if (pending.size === 0 && typeof created.unref === 'function') created.unref();
126
+ if (worker !== created || stopping || !running || running.id !== message?.id) return;
127
+ completeRunning(message.ok && message.bytes ? {
128
+ bytes: Buffer.from(message.bytes),
129
+ contentType: 'image/png',
130
+ resized: true,
131
+ cropped: !!message.cropped
132
+ } : null);
133
+ dispatchNext();
134
+ });
135
+ created.on('error', () => { if (worker === created) stopWorker(); });
136
+ created.on('exit', () => {
137
+ if (worker !== created) return;
138
+ worker = null;
139
+ stopping = false;
140
+ completeRunning(null);
141
+ dispatchNext();
131
142
  });
132
- // 旧 Worker 被 close/重启后,它的 exit 不能把新 Worker 的请求一起结算掉。
133
- created.on('error', () => { if (worker === created) settleAll(); });
134
- created.on('exit', () => { if (worker === created) settleAll(); });
135
143
  return created;
136
144
  }
137
145
 
138
- function releaseWorkerIfIdle() {
139
- if (pending.size === 0 && worker && typeof worker.unref === 'function') worker.unref();
146
+ function dispatchNext() {
147
+ if (stopping || running) return;
148
+ const job = queue.values().next().value;
149
+ if (!job) {
150
+ worker?.unref();
151
+ return;
152
+ }
153
+ queue.delete(job.id);
154
+ running = job;
155
+ try {
156
+ worker ??= createWorker();
157
+ worker.ref();
158
+ // 独立的 ArrayBuffer 可以转移,同时保留调用方的原图(包括 Buffer 池切片)。
159
+ const copy = new Uint8Array(job.bytes);
160
+ worker.postMessage({ id: job.id, bytes: copy.buffer, width: job.width, height: job.height, mode: job.mode }, [copy.buffer]);
161
+ } catch (_error) {
162
+ completeRunning(null);
163
+ if (worker) stopWorker();
164
+ else clearQueue();
165
+ }
140
166
  }
141
167
 
142
168
  /**
@@ -150,46 +176,33 @@ function releaseWorkerIfIdle() {
150
176
  * @returns {Promise<{bytes:Buffer,contentType:string,resized:boolean,cropped:boolean}|null>}
151
177
  */
152
178
  export function resizeInWorker(bytes, width, height, mode, options = {}) {
153
- if (!Buffer.isBuffer(bytes) || !targetOk(Number(width), Number(height))) return Promise.resolve(null);
154
- let active;
155
- try {
156
- active = ensureWorker();
157
- } catch (_error) {
179
+ const targetWidth = Number(width);
180
+ const targetHeight = Number(height);
181
+ if (!targetOk(targetWidth, targetHeight)) return Promise.resolve(null);
182
+ const header = pngHeaderOf(bytes);
183
+ if (!header || header.bitDepth !== 8 || header.interlace !== 0 || !targetOk(header.width, header.height)) {
158
184
  return Promise.resolve(null);
159
185
  }
160
- const requestedTimeout = options && options.timeoutMs !== undefined ? Number(options.timeoutMs) : DEFAULT_TIMEOUT_MS;
161
- if (!Number.isFinite(requestedTimeout) || requestedTimeout <= 0) return Promise.resolve(null);
162
- const timeoutMs = requestedTimeout;
186
+ const timeoutMs = options?.timeoutMs === undefined ? DEFAULT_TIMEOUT_MS : Number(options.timeoutMs);
187
+ if (!Number.isFinite(timeoutMs) || timeoutMs <= 0) return Promise.resolve(null);
163
188
  return new Promise((resolve) => {
164
189
  const id = nextId++;
165
- if (typeof active.ref === 'function') active.ref();
166
190
  const timer = setTimeout(() => {
167
- if (!pending.has(id)) return;
168
- pending.delete(id);
169
- releaseWorkerIfIdle();
170
- resolve(null);
191
+ if (queue.delete(id)) {
192
+ resolve(null);
193
+ } else if (running?.id === id) {
194
+ stopWorker();
195
+ completeRunning(null);
196
+ }
171
197
  }, timeoutMs);
172
- if (typeof timer.unref === 'function') timer.unref();
173
- pending.set(id, { id: id, resolve: resolve, timer: timer });
174
- // 复制一份再转移:Buffer 可能来自共享的 Buffer 池,转移共享底层内存会破坏其他引用。
175
- // 复制到独立的 ArrayBuffer 再转移:Buffer 可能来自 Node 的共享池,
176
- // 池底层的 ArrayBuffer 带 byteOffset,直接放进 transfer list 会被拒绝。
177
- const copy = new Uint8Array(bytes);
178
- try {
179
- active.postMessage({ id: id, bytes: copy.buffer, width: Number(width), height: Number(height), mode: mode }, [copy.buffer]);
180
- } catch (_error) {
181
- pending.delete(id);
182
- clearTimeout(timer);
183
- releaseWorkerIfIdle();
184
- resolve(null);
185
- }
198
+ queue.set(id, { id, bytes, width: targetWidth, height: targetHeight, mode, resolve, timer });
199
+ dispatchNext();
186
200
  });
187
201
  }
188
202
 
189
- /** 关闭 Worker;测试和插件卸载时调用。进行中的请求回 null,由调用方同步兜底。 */
203
+ /** 关闭 Worker,未完成的请求返回 null。以后提交的请求可以启动新 Worker。 */
190
204
  export function closeImageWorker() {
191
- if (!worker) return;
192
- try { worker.terminate(); } catch (_error) { /* ignore */ }
193
- if (typeof worker.unref === 'function') worker.unref();
194
- settleAll();
205
+ stopWorker();
206
+ completeRunning(null);
207
+ clearQueue();
195
208
  }