GithubHelp home page GithubHelp logo

promise's Introduction

Promise

Package Promise - lisp (JSCL) wrap for JavaScript Promise.

It is intended for use in the Moren environment.

Status

Development

Compilation

   (lores:qload :promise :storejs t)
   (lores:modlink :promise "prom.js")

Use

(setq p1 (promise:make
            (lambda (res rej)
                 (#j:setTimeout
                     (lambda () (case (random 2)
                                  (0 (funcall rej "no"))
                                  (1 (funcall res "yes")))) 100)))
(promise:is-promise p1)
;;=> t

(promise:then p1 
              (lambda (x) (print (list 'accepted x)))
              (lambda (x) (print (list 'rejected x)))))

(promise:_catch
    (promise:then-resolve p1 (lambda (x) (print (list 'accepted x))))
    (lambda (x) (print (list 'rejected x))))

(promise:then-resolve (promise:all (promise:resolve 1) (promise:resolve 2)))

Promisify

For example we use pify.

                                                             
(setf #j:pify (require "pify"))

(defun somefn (arg1 arg2 callback &rest other)
    ;; some code
    (if flag 
       (funcall callback nil arg1) ;; its (resolve arg1)
       (funcall callback arg2 nil)) ;; its (reject arg2)
))

(promise:then (funcall (#j:pify #'somefn) 123 456)
              (lambda (x) (print x))  ;; => resolve 123
              (lambda (x) (print x))) ;; => rejected 456

Copyright

Copyright © 2017,2018 Vladimir Mezentsev

License

GNU General Public License v3.0

promise's People

Contributors

vlad-km avatar

Stargazers

 avatar

Watchers

 avatar

promise's Issues

Workaround

for jscl:make-new
js Promise dasnt work with (make-new #j:Promise)

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.