1 Star 0 Fork 1.5K

及时雨/万岳在线教育系统UNI-APP开源版

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
.hbuilderx
.idea
common
components
js_sdk/hyoga-uni-socket_io
node_modules
@hyoga
after
test
.npmignore
.travis.yml
LICENCE
README.md
index.js
package.json
arraybuffer.slice
async-limiter
backo2
base64-arraybuffer
blob
component-bind
component-emitter
component-inherit
debug
engine.io-client
engine.io-parser
has-binary2
has-cors
indexof
isarray
ms
parseqs
parseuri
socket.io-client
socket.io-parser
to-array
ws
xmlhttprequest-ssl
yeast
.DS_Store
packageB
pages
setting
static
store
unpackage
.DS_Store
144209_cf74cc99_8162876.png
App.vue
LICENSE
README.md
main.js
manifest.json
package-lock.json
pages.json
qiniuUploader.js
uni.scss
version
wanyue_education_uniapp(new).rar
功能表.jpg
开源版.jpg
演示链接.png
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README

After Build Status

Invoke callback after n calls

Status: production ready

Example

var after = require("after")
var db = require("./db") // some db.

var updateUser = function (req, res) {
  // use after to run two tasks in parallel,
  // namely get request body and get session
  // then run updateUser with the results
  var next = after(2, updateUser)
  var results = {}
  
  getJSONBody(req, res, function (err, body) {
    if (err) return next(err)
    
    results.body = body
    next(null, results)
  })
  
  getSessionUser(req, res, function (err, user) {
    if (err) return next(err)
    
    results.user = user
    next(null, results)
  })
  
  // now do the thing!
  function updateUser(err, result) {
    if (err) {
      res.statusCode = 500
      return res.end("Unexpected Error")
    }
    
    if (!result.user || result.user.role !== "admin") {
      res.statusCode = 403
      return res.end("Permission Denied")
    }
    
    db.put("users:" + req.params.userId, result.body, function (err) {
      if (err) {
        res.statusCode = 500
        return res.end("Unexpected Error")
      }
      
      res.statusCode = 200
      res.end("Ok")  
    })   
  }
}

Naive Example

var after = require("after")
    , next = after(3, logItWorks)

next()
next()
next() // it works

function logItWorks() {
    console.log("it works!")
}

Example with error handling

var after = require("after")
    , next = after(3, logError)

next()
next(new Error("oops")) // logs oops
next() // does nothing

// This callback is only called once.
// If there is an error the callback gets called immediately
// this avoids the situation where errors get lost.
function logError(err) {
    console.log(err)
}

Installation

npm install after

Tests

npm test

Contributors

  • Raynos
  • defunctzombie

MIT Licenced

马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
JavaScript
1
https://gitee.com/timely-raintushu/wanyue_education_uniapp.git
git@gitee.com:timely-raintushu/wanyue_education_uniapp.git
timely-raintushu
wanyue_education_uniapp
万岳在线教育系统UNI-APP开源版
newone

搜索帮助