How to run Meteor insert within a Fiber

0 votes

I have some code in init.js under the "lib" folder to take an event from the web3/ethereum package and store it in a collection. I've included the contextual information about web3/ethereum.

var events = contract_instance.allEvents([]);

events.watch(function(error, event){
  if (!error)
    console.log(event.args);

var event_object_value1 = event.args.value1;
//everything up to this point works fine.  event_object is in a json format.

//inserting the value into a collection on the server side like this is what causes the error.
collection.insert({"key": value1});
});

The last line produces the Meteor code must always run within a Fiber.error. Normally, I would insert using a Meteor Method, but I suspect I would get the same error when actually doing the insert.

I haven't been able to get my code within a fiber correctly. I've tried to follow this example here, but I think it's just way to above my understanding of Meteor: https://meteorhacks.com/fibers-eventloop-and-meteor/

Sep 28, 2018 in Blockchain by digger
• 26,740 points
720 views

1 answer to this question.

0 votes

Just replace

events.watch(function(error, event) {
  ...
});

with

events.watch(Meteor.bindEnvironment(function(error, event) {
  ...
}));

Meteor.bindEnvironment ensures that the wrapped function runs within a fiber.

answered Sep 28, 2018 by slayer
• 29,370 points

Related Questions In Blockchain

0 votes
2 answers

How to set permissions within a blockchain?

There are blockchains that allow defining permissions. Hyperledger ...READ MORE

answered Aug 28, 2018 in Blockchain by Michael
1,064 views
0 votes
1 answer

How to run smart contract function using nethereum to return a result?

Try this: var result = getUserAtIndex.CallAsync<byte[]>(123) ...READ MORE

answered Oct 24, 2018 in Blockchain by Omkar
• 69,230 points
2,005 views
0 votes
1 answer

How to run a Javascript in truffle console?

There are two ways to do this. You ...READ MORE

answered Jan 24, 2019 in Blockchain by Omkar
• 69,230 points
2,402 views
0 votes
1 answer

How to make sure transactions take no fee in a private Ethereum blockchain?

In a private ethereum network you have ...READ MORE

answered Mar 26, 2018 in Blockchain by Christine
• 15,790 points

edited Mar 26, 2018 by Christine 1,512 views
0 votes
1 answer

Hyperledger Sawtooth vs Quorum in concurrency and speed Ask

Summary: Both should provide similar reliability of ...READ MORE

answered Sep 26, 2018 in IoT (Internet of Things) by Upasana
• 8,620 points
1,394 views
0 votes
1 answer

How to create a Genesis Block in a Private Network?

{     "nonce": "0x0000000000000042",     "difficulty": "0x000000100",     "alloc": {     },     "mixhash": "0x0000000000000000000000000000000000000000000000000000000000000000",     "coinbase": "0x0000000000000000000000000000000000000000",     "timestamp": "0x00",     "parentHash": ...READ MORE

answered Jul 12, 2018 in Blockchain by digger
• 26,740 points
1,962 views
0 votes
1 answer

Invalid Batch or signature in Savtooth

This will solve your problem import org.apache.commons.codec.binary.Hex; Transaction txn ...READ MORE

answered Aug 1, 2018 in Blockchain by digger
• 26,740 points
902 views
0 votes
1 answer
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP