Skip to content
Advertisement

Calling external function from async.waterfall

I’m somewhat new to JS and working with an existing forked library (which is very complicated and poorly documented) – so please bear with me.

I’m working on a mining pool system, and specifically adding a feature where users can set a custom payout amount instead of the lower pool limit. I’ve already sorted writing that value for a users worker address into redis.

What I’m trying to do now is add logic that will:

  1. Use the worker Address that did work to see if they set a custom payout value (my external function below)
  2. If it’s set, some logic to determine if they should be paid immediately or add it to their balance

The existing waterfall script is here: https://github.com/mardock2009/Ravencoin-Pool/blob/master/libs/paymentProcessor.js#L575

Before the waterfall, i’m adding a function similar to this (i’ve tried many iterations):

JavaScript

Then at around line 575, i’m calling it (maybe?):

JavaScript

And then finally, some if/elseif logic to handle the different cases:

JavaScript

The main issue I’m having is I cant get values back from redis calling it inside the waterfall. I’m assuming because it’s async andIi’m not writing async code – which also causes it to not necessarily run in order when I need the values.

Again, I know this is a mess and I’m probably going about this all wrong, so hopefully someone has some insight for this poor noob.

Advertisement

Answer

You can use async.each()

JavaScript

and In ‘getCustomPayoutAmount’, ‘cback()` should be called within the callback of ‘redisClient.hget()’ like below

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement