<commit_before>
var assert = require('assert')
  , ffi = require('../')

describe('Callback', function () {

  afterEach(gc)

  it('should create a C function pointer from a JS function', function () {
    var callback = ffi.Callback('void', [ ], function (val) { })
    assert(Buffer.isBuffer(callback))
  })

  it('should be invokable', function () {
    var callback = ffi.Callback('int', [ 'int' ], function (val) {
      return Math.abs(val)
    })
    var func = ffi.ForeignFunction(callback, 'int', [ 'int' ])
    assert.equal(1234, func(-1234))
  })

})<commit_msg>test: add test for a Callback being invoked on another thread<commit_after>
var assert = require('assert')
  , ffi = require('../')

describe('Callback', function () {

  afterEach(gc)

  it('should create a C function pointer from a JS function', function () {
    var callback = ffi.Callback('void', [ ], function (val) { })
    assert(Buffer.isBuffer(callback))
  })

  it('should be invokable by an ffi\'d ForeignFunction', function () {
    var funcPtr = ffi.Callback('int', [ 'int' ], Math.abs)
    var func = ffi.ForeignFunction(funcPtr, 'int', [ 'int' ])
    assert.equal(1234, func(-1234))
  })

  it('should be invokable asynchronously by an ffi\'d ForeignFunction', function () {
    var funcPtr = ffi.Callback('int', [ 'int' ], Math.abs)
    var func = ffi.ForeignFunction(funcPtr, 'int', [ 'int' ])
    func.async(-9999, function (err, res) {
      assert.equal(null, err)
      assert.equal(9999, res)
    })
  })

})
{'fraction_non_alphanumeric': 0.17087765957446807, 'fraction_numerical': 0.015957446808510637, 'mean_word_length': 3.533132530120482, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3778789', 'n_tokens_mistral': 509, 'n_tokens_neox': 480, 'n_words': 128}