Hamsters.js
  • Home
  • About
  • Services
  • Examples
    • Atomic Operations
    • Collatz Conjecture
    • Fibonacci Sequence
    • Mandelbrot Set
    • Square Root
  • Wiki
  • Donate
  • Contact
Login
Register

Hamsters.js Wiki

  • Installing Hamsters

    • HTML
    • React Native
    • Node.js
  • Using Hamsters

    • Initializing
    • The Basics
    • Restructuring Standard Functions
    • Promises
    • Sorting
    • Persistence
    • Transferable Objects
    • Atomic Operations
    • Memoization
    • Debugging
    • Limitations

Promises

Hamsters.js also supports the use of promises using a method called hamsters.promise, the traditional method hamsters.run makes use of callbacks. Promises can give you more sequential control of your application.

            
              var params = {
                array: [1, 2, 3, 4]
              };
              hamsters.promise(params, function() {
                for(var i = 0; i < params.array; i++) {
                  rtn.data.push(params.array[i] * 4);
                }
              }).then(function(results) {
                  console.log(results);
              }).catch(function(error) {
                  console.error(error);
              });
            
          

This should enable the use of async await as well giving you the power to take the above example and make it even easier.

            
              var params = {
                array: [1, 2, 3, 4];
              };
              var results = await hamsters.promise(params, functionToRun);
            
          
  • Twitter:

  • Recent Updates

    Hamsters.js v5.6.1 Released!

    New React Native Hamsters Release v1.0.9!

    Subscribe To Updates

    Stay in the Loop! Subscribe for Updates on New Releases and Terms of Service Changes.

    © 2015 - 2024 asmithdev | All rights reserved.
    • Home
    • About
    • Privacy
    • License
    • Invest