sptc 0.0.12 → 0.0.14

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.
package/bin/sptcd.js CHANGED
@@ -1,4 +1,4 @@
1
- #!/usr/bin/env node
1
+ #!/usr/bin/env node
2
2
 
3
3
  const {FastCGI, FastCGI_FPM}=require('../dist/httpServer')
4
4
  const {Command}=require('commander')
package/engine/index.js CHANGED
@@ -42,7 +42,7 @@ function executeSptcFileEx(...x) {
42
42
  if(!is_str && typeof x==='string') x=Buffer.concat(x)
43
43
  xbuf.push(x)
44
44
  }
45
- resolve(xbuf)
45
+ resolve(is_str? xbuf.join(''): Buffer.concat(xbuf))
46
46
  }
47
47
  x[2].onError=e=>{
48
48
  onError && onError(e)
@@ -2,7 +2,7 @@ const _module=require('module')
2
2
  const vm=require('vm')
3
3
  const path=require('path')
4
4
  const Compiler=require('./compiler')
5
- const {generate_uuid}=require('../utils')
5
+ const {generate_uuid, PromiseWithResolvers}=require('../utils')
6
6
 
7
7
  /*
8
8
  const tt={x: 2, b: [2, 5], c: _=>2, d: /xx/ig}
@@ -190,6 +190,11 @@ function buildContext(ctx0, option) {
190
190
  }
191
191
  priv.syncs.push(...x)
192
192
  },
193
+ Lock: _=>{
194
+ const lock=PromiseWithResolvers()
195
+ priv.syncs.push(lock.promise)
196
+ return _=>lock.resolve()
197
+ },
193
198
  }
194
199
 
195
200
  ctx.defer=fn=>{
@@ -313,6 +318,7 @@ function executeVm(vm, ctx, priv) {
313
318
  onError(e)
314
319
  }
315
320
 
321
+ if(!isMaster) return;
316
322
  for(let fn of priv._defers.splice(0)) {
317
323
  try{
318
324
  fn()
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sptc",
3
- "version": "0.0.12",
3
+ "version": "0.0.14",
4
4
  "description": "Simple Pretreat Toolkit CLI",
5
5
  "main": "index.js",
6
6
  "engines": {
package/utils/base.js CHANGED
@@ -53,6 +53,15 @@ function getLocalIpv4Addresses() {
53
53
  return Object.keys(rr)
54
54
  }
55
55
 
56
+ function PromiseWithResolvers() {
57
+ let _resolve, _reject
58
+ const promise=new Promise((resolve, reject)=>{
59
+ _resolve=resolve
60
+ _reject=reject
61
+ })
62
+ return {promise, resolve: _resolve, reject: _reject}
63
+ }
64
+
56
65
  module.exports={
57
66
  readTextFile,
58
67
  mtime,
@@ -62,4 +71,5 @@ module.exports={
62
71
  generate_uuid,
63
72
  getExtension,
64
73
  getLocalIpv4Addresses,
74
+ PromiseWithResolvers,
65
75
  }