<commit_before>// Copyright 2015-2016 Diffeo, Inc.
// This software is released under an MIT/X11 open source license.

package memory

import (
	"github.com/diffeo/go-coordinate/coordinate"
)

type workUnit struct {
	name           string
	data           map[string]interface{}
	meta           coordinate.WorkUnitMeta
	activeAttempt  *attempt
	attempts       []*attempt
	workSpec       *workSpec
	availableIndex int
	deleted        bool
}

// coordinate.WorkUnit interface:

func (unit *workUnit) Name() string {
	return unit.name
}

func (unit *workUnit) Data() (map[string]interface{}, error) {
	if unit.activeAttempt != nil && unit.activeAttempt.data != nil {
		return unit.activeAttempt.data, nil
	}
	return unit.data, nil
}

func (unit *workUnit) WorkSpec() coordinate.WorkSpec {
	return unit.workSpec
}

func (unit *workUnit) do(f func() error) error {
	globalLock(unit)
	defer globalUnlock(unit)
	if unit.deleted || unit.workSpec.deleted || unit.workSpec.namespace.deleted {
		return coordinate.ErrGone
	}
	return f()
}

func (unit *workUnit) Status() (status coordinate.WorkUnitStatus, err error) {
	err = unit.do(func() error {
		unit.workSpec.expireUnits()
		status = unit.status()
		return nil
	})
	return
}
<commit_msg>memory buglet: WorkUnit.Data() correctly returns ErrGone<commit_after>// Copyright 2015-2016 Diffeo, Inc.
// This software is released under an MIT/X11 open source license.

package memory

import (
	"github.com/diffeo/go-coordinate/coordinate"
)

type workUnit struct {
	name           string
	data           map[string]interface{}
	meta           coordinate.WorkUnitMeta
	activeAttempt  *attempt
	attempts       []*attempt
	workSpec       *workSpec
	availableIndex int
	deleted        bool
}

// coordinate.WorkUnit interface:

func (unit *workUnit) Name() string {
	return unit.name
}

func (unit *workUnit) Data() (data map[string]interface{}, err error) {
	err = unit.do(func() error {
		data = unit.data
		if unit.activeAttempt != nil && unit.activeAttempt.data != nil {
			data = unit.activeAttempt.data
		}
		return nil
	})
	return
}

func (unit *workUnit) WorkSpec() coordinate.WorkSpec {
	return unit.workSpec
}

func (unit *workUnit) do(f func() error) error {
	globalLock(unit)
	defer globalUnlock(unit)
	if unit.deleted || unit.workSpec.deleted || unit.workSpec.namespace.deleted {
		return coordinate.ErrGone
	}
	return f()
}

func (unit *workUnit) Status() (status coordinate.WorkUnitStatus, err error) {
	err = unit.do(func() error {
		unit.workSpec.expireUnits()
		status = unit.status()
		return nil
	})
	return
}

{'fraction_non_alphanumeric': 0.11314865392118612, 'fraction_numerical': 0.007803355442840421, 'mean_word_length': 3.6115107913669067, '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': '5068492', 'n_tokens_mistral': 863, 'n_tokens_neox': 823, 'n_words': 223}