# Pulse getting lost in program

**URL:** https://forum.xod.io/t/pulse-getting-lost-in-program/4460
**Category:** XOD Programming Questions
**Created:** [September 24, 2020, 4:15pm UTC](https://forum.xod.io/t/pulse-getting-lost-in-program/4460 "2020-09-24T16:15:57Z")
**Posts on this page:** 13
**Page:** 1

<div class="post-metadata">

### Author: ![gweimer](https://avatars.discourse-cdn.com/v4/letter/g/a9adbd/32.png) [@gweimer](https://forum.xod.io/u/gweimer)
#### Post date: [September 24, 2020, 4:15pm UTC](https://forum.xod.io/t/pulse-getting-lost-in-program/4460/1 "2020-09-24T16:15:57Z")

</div>

Is this a bug? Program seems to be dropping pulses.  
 ![image](https://canada1.discourse-cdn.com/flex027/uploads/xod/original/2X/7/7fbbb6023f5647a6a183f96ae326dd90743a58e4.png)  
As you can see from the counters, the pulse gets to the 2nd max-buffer, but never goes beyond that. I would assume programing error, except it is the same node that works in one case, but not in an identical use case.

The max-buffer code simply takes PUSH pulse, defers it, then passes it to DONE, so I don’t see how it could be lost through error or similar issue.  
 ![image](https://canada1.discourse-cdn.com/flex027/uploads/xod/original/2X/2/2b00768201a7177ab91e4f0c4fe8bf373279f385.png)

I was having the same issue with 0.34.?, but upgrading to 0.35.2 didn’t help. Same issue in simulation and upload to UNO.

---

<div class="post-metadata">

### Author: ![danya](https://avatars.discourse-cdn.com/v4/letter/d/7ba0ec/32.png) [@danya](https://forum.xod.io/u/danya)
#### Post date: [September 24, 2020, 5:34pm UTC](https://forum.xod.io/t/pulse-getting-lost-in-program/4460/2 "2020-09-24T17:34:56Z")

</div>

Hello. I removed the defer from the max-buffer. It seems to work.

 ![image](https://canada1.discourse-cdn.com/flex027/uploads/xod/original/2X/e/e63d1223c3a437577827f9ddd90d15e310959ed9.png)

---

<div class="post-metadata">

### Author: ![gweimer](https://avatars.discourse-cdn.com/v4/letter/g/a9adbd/32.png) [@gweimer](https://forum.xod.io/u/gweimer)
#### Post date: [September 24, 2020, 6:42pm UTC](https://forum.xod.io/t/pulse-getting-lost-in-program/4460/3 "2020-09-24T18:42:39Z")

</div>

That’s…disconcerting… Besides being just wrong that defer would drop a pulse completely, that “fix” means that DONE will likely pulse before NEW gets updated…

---

<div class="post-metadata">

### Author: ![danya](https://avatars.discourse-cdn.com/v4/letter/d/7ba0ec/32.png) [@danya](https://forum.xod.io/u/danya)
#### Post date: [September 24, 2020, 6:59pm UTC](https://forum.xod.io/t/pulse-getting-lost-in-program/4460/4 "2020-09-24T18:59:56Z")

</div>

The defer is needed in order to create cycles, isn’t it? Why use defer in max buffer at all? There seems to be no feedback, everything goes sequentially and without cycles.  
I decided to make logic out of defers. Here’s what it gives me:

 ![image](https://canada1.discourse-cdn.com/flex027/uploads/xod/original/2X/b/bb3e010273250d0ef0cc0dedefe3220d1a86fde9.png)  
Everything works exactly until the third defer. This is really strange.

---

<div class="post-metadata">

### Author: ![danya](https://avatars.discourse-cdn.com/v4/letter/d/7ba0ec/32.png) [@danya](https://forum.xod.io/u/danya)
#### Post date: [September 24, 2020, 7:04pm UTC](https://forum.xod.io/t/pulse-getting-lost-in-program/4460/5 "2020-09-24T19:04:46Z")

</div>

I decided to put the delays between defers, for a very short time. And everything worked.

 ![image](https://canada1.discourse-cdn.com/flex027/uploads/xod/original/2X/f/f07db1abcbade3748ff985e22d947cba65306231.png)

---

<div class="post-metadata">

### Author: ![gweimer](https://avatars.discourse-cdn.com/v4/letter/g/a9adbd/32.png) [@gweimer](https://forum.xod.io/u/gweimer)
#### Post date: [September 24, 2020, 7:12pm UTC](https://forum.xod.io/t/pulse-getting-lost-in-program/4460/6 "2020-09-24T19:12:29Z")

</div>

The current buffer value does loop back to the top of the patch, so defer should be used there. Without a defer before DONE, this results in DONE pulse before MEM is updated, which is not a problem in this example where MEM is just tied to watch node, but would be a problem if DONE triggered an action using MEM value. In this case, the buffer defer could be moved after the from-bus-OUT, but without defer on pulse wire, there is still the chance that DONE will pulse before MEM is updated.

Good thought to narrow the problem down to just pulse passing through 3 defer nodes without all the extra code.

---

<div class="post-metadata">

### Author: ![cesars](https://avatars.discourse-cdn.com/v4/letter/c/f05b48/32.png) [@cesars](https://forum.xod.io/u/cesars)
#### Post date: [September 25, 2020, 5:11pm UTC](https://forum.xod.io/t/pulse-getting-lost-in-program/4460/7 "2020-09-25T17:11:55Z")

</div>

A bridge from `input` to `output` produces a defer, I pass with the nodes of output-self.

if the implementation is in C ++ …

```auto
emitValue <output_OUT> (ctx, getValue<input_IN> (ctx)); 

```

no delay occurs.

---

<div class="post-metadata">

### Author: ![gweimer](https://avatars.discourse-cdn.com/v4/letter/g/a9adbd/32.png) [@gweimer](https://forum.xod.io/u/gweimer)
#### Post date: [September 25, 2020, 7:33pm UTC](https://forum.xod.io/t/pulse-getting-lost-in-program/4460/8 "2020-09-25T19:33:08Z")

</div>

I think you are saying a link from input node to output node in XOD code has an implied defer node, so manually adding defer is not needed. That provides a long-term work-around for my code, but doesn’t fix the problem that a chain of 3 defer nodes will lose a pulse as demonstrated by @danya code above.

---

<div class="post-metadata">

### Author: ![cesars](https://avatars.discourse-cdn.com/v4/letter/c/f05b48/32.png) [@cesars](https://forum.xod.io/u/cesars)
#### Post date: [September 25, 2020, 8:55pm UTC](https://forum.xod.io/t/pulse-getting-lost-in-program/4460/9 "2020-09-25T20:55:57Z")

</div>

the `defer(pulse)` node has an implementation for error detection, could that be it? I have not tried with previous versions

---

<div class="post-metadata">

### Author: ![gweimer](https://avatars.discourse-cdn.com/v4/letter/g/a9adbd/32.png) [@gweimer](https://forum.xod.io/u/gweimer)
#### Post date: [September 25, 2020, 9:12pm UTC](https://forum.xod.io/t/pulse-getting-lost-in-program/4460/10 "2020-09-25T21:12:13Z")

</div>

If there were an error in defer, wouldn’t the node turn red in debug mode?

What could cause an error in defer??? has-error doesn’t seem to work with pulse as input.

---

<div class="post-metadata">

### Author: ![cesars](https://avatars.discourse-cdn.com/v4/letter/c/f05b48/32.png) [@cesars](https://forum.xod.io/u/cesars)
#### Post date: [September 25, 2020, 9:58pm UTC](https://forum.xod.io/t/pulse-getting-lost-in-program/4460/11 "2020-09-25T21:58:18Z")

</div>

There would not be an error, but when checking if there is an error to pass it to the next node, it happens that the pulse is lost after the 3rd cycle. Is what i believe

---

<div class="post-metadata">

### Author: ![evgenykochetkov](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.xod.io/evgenykochetkov/32/14_2.png) [@evgenykochetkov](https://forum.xod.io/u/evgenykochetkov)
#### Post date: [October 1, 2020, 2:32pm UTC](https://forum.xod.io/t/pulse-getting-lost-in-program/4460/12 "2020-10-01T14:32:03Z")

</div>

Hi everyone.

Yes, this is a bug. After looking at the generated code, I discovered that nodes are evaluated in the following order:

 ![Screen Shot 2020-09-30 at 20.18.14](https://canada1.discourse-cdn.com/flex027/uploads/xod/original/2X/2/24a236403fbea81b470c90ce7220e4a4160d22f2.png)  
The first defer in chain is executed last, and because of that is able to pass a pulse only to the next one.

While I am working on the fix, the temporary solution would be creating a custom node that delays a pulse until the next transaction, something like

```cpp
node {
    void evaluate(Context ctx) {
        if (isInputDirty<input_IN>(ctx)) {
            setTimeout(ctx, 0);
        }

        if (isTimedOut(ctx)) {
            emitValue<output_OUT>(ctx, 1);
        }
    }
}

```

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex027/uploads/xod/original/1X/eb7348baa04192c2ef932d1db54d44f09f8a7888.png) [@system](https://forum.xod.io/u/system)
#### Post date: [October 31, 2020, 2:32pm UTC](https://forum.xod.io/t/pulse-getting-lost-in-program/4460/13 "2020-10-31T14:32:12Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
