Code Monkey home page Code Monkey logo

ng-mutex-lock's Introduction

源自

由于对项目中所有的ajax请求进行了错误拦截,并弹出错误信息,导致了当服务器宕机时,会有无数个错误弹窗爆发出来,因此就想起互斥线程这个东西,于是做了个ng版的“互斥锁”。

模块名 mutexLockServiceModule

服务名 mutexLockService

Demo

//首先将你的函数改造成返回值为Promise的异步函数。
//例如,你的函数是hello
function hello(){
    console.log("hallo world!");
};

//改造成异步函数
var fn = function(){
    var defer = $q.defer();
    console.log("hallo world!");//hello函数的内容
    defer.resolve();
    return defer.promise;
};

//将fn加上互斥锁
var lockedHello = mutexLockService.create(fn);

//然后……
//没有了

详情

还提供了remove和query方法,用来删除和查询互斥锁

请移步代码,简短寥寥几行

ng-mutex-lock's People

Contributors

heekei avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.