mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-01-23 02:35:49 +00:00
feature(markdown) move out parse to worker
This commit is contained in:
parent
560dd8fddc
commit
e46d104cc7
5 changed files with 18 additions and 15 deletions
|
|
@ -1,7 +1,7 @@
|
|||
'use strict';
|
||||
|
||||
const DIR_ROOT = __dirname + '/../';
|
||||
const fs = require('fs');
|
||||
const {join} = require('path');
|
||||
const {
|
||||
callbackify,
|
||||
promisify,
|
||||
|
|
@ -9,11 +9,19 @@ const {
|
|||
|
||||
const pullout = require('pullout');
|
||||
const ponse = require('ponse');
|
||||
const markdown = require('markdown-it')();
|
||||
const threadIt = require('thread-it');
|
||||
|
||||
const readFile = promisify(fs.readFile);
|
||||
const parse = threadIt(join(__dirname, 'worker'));
|
||||
|
||||
const root = require('./root');
|
||||
const root = require('../root');
|
||||
|
||||
threadIt.init();
|
||||
|
||||
// warm up
|
||||
parse('');
|
||||
|
||||
const DIR_ROOT = __dirname + '/../../';
|
||||
|
||||
module.exports = callbackify(async (name, rootDir, request) => {
|
||||
check(name, request);
|
||||
|
|
@ -48,18 +56,9 @@ async function onGET(request, name, root) {
|
|||
|
||||
async function onPUT(request) {
|
||||
const data = await pullout(request);
|
||||
|
||||
return parse(data);
|
||||
}
|
||||
|
||||
const parse = promisify((data, callback) => {
|
||||
process.nextTick(() => {
|
||||
const md = markdown.render(data);
|
||||
|
||||
callback(null, md);
|
||||
});
|
||||
});
|
||||
|
||||
function check(name, request) {
|
||||
if (typeof name !== 'string')
|
||||
throw Error('name should be string!');
|
||||
|
|
@ -7,11 +7,11 @@ const {promisify} = require('util');
|
|||
|
||||
const tryToCatch = require('try-to-catch');
|
||||
|
||||
const markdown = require('./markdown');
|
||||
const markdown = require('.');
|
||||
|
||||
const _markdown = promisify(markdown);
|
||||
const fixtureDir = path.join(__dirname, 'fixture', 'markdown');
|
||||
const cloudcmd = require('..');
|
||||
const fixtureDir = path.join(__dirname, 'fixture');
|
||||
const cloudcmd = require('../..');
|
||||
const config = {
|
||||
auth: false,
|
||||
};
|
||||
4
server/markdown/worker.js
Normal file
4
server/markdown/worker.js
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
'use strict';
|
||||
|
||||
const markdownIt = require('markdown-it')();
|
||||
module.exports = (a) => markdownIt.render(a);
|
||||
Loading…
Add table
Add a link
Reference in a new issue